Wednesday, April 29, 2020

vector multiplication in machine learning using python

# add vectors
from numpy import array
a = array([1, 2, 3])
print(a)
b = array([1, 2, 3])
print(b)
c = a + b
print(c)
[1 2 3]
[1 2 3]
[2 4 6]
In [2]:
print(type(c))
<class 'numpy.ndarray'>
In [3]:
d=array([4,5,6])
e=array([1,2,3])
f=d-e
print(f)
[3 3 3]
In [4]:
g=a/b
print(g)
[1. 1. 1.]
In [5]:
#vector multiplication
h=d*e
print(h)
[ 4 10 18]
In [6]:
# vector-scalar multiplication
from numpy import array
a = array([1, 2, 3])
print(a)
s = 0.5
print(s)
c = s * a
print(c)
[1 2 3]
0.5
[0.5 1.  1.5]
In [ ]:
 

Monday, April 27, 2020

entry with three form fields using tkinter in python

from tkinter import *
import pymysql


def create_table():
    conn=pymysql.connect(host="localhost",user="root",password="",db="sslabs")
    mycursor=conn.cursor()
    #mycursor.execute("CREATE TABLE student2 (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255),standard VARCHAR(255), sub VARCHAR(255) )")
    sql = "INSERT INTO student2 (name, standard,sub) VALUES (%s, %s,%s)"
 
    #print("First Name: %s\nstandard:%s\nsubject:%s" % (e1.get(),e2.get(),e3.get()))
    name=e1.get()
    standard=e2.get()
    sub=e3.get()
    val = (name, standard, sub)
    mycursor.execute(sql, val)
    conn.commit()
    print(mycursor.rowcount, "record inserted.")

def show_entry_fields():
    #print("First Name: %s\nstandard:%s\nsubject:%s" % (e1.get(),e2.get(),e3.get()))
    query = "SELECT * FROM student2"
    ## getting records from the table
    mycursor.execute(query)
    ## fetching all records from the 'cursor' object
    records = mycursor.fetchall()
    ## Showing the data
    for record in records:
        print(record)

master=Tk()
master.title("Basic Entry Widget")


Label(master , text="First Name").grid(row=0)
Label(master , text="standard").grid(row=1)
Label(master , text="sub").grid(row=2)

e1=Entry(master)
name=e1.grid(row=0,column=1)
e2=Entry(master)
standard = e2.grid(row=1,column=1)
e3=Entry(master)
sub = e3.grid(row=2,column=1)

Button(master,text='Quit', command=master.quit).grid(row=3,column=0,sticky=W,pady=4)
Button(master,text='Show', command=show_entry_fields).grid(row=3,column=1,sticky=W,pady=4)
Button(master,text='Insert', command=create_table).grid(row=3,column=2,sticky=W,pady=4)


mainloop()






 








Friday, April 24, 2020

violin plot using seaborn in datascience in python

import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.violinplot(x=tips["total_bill"])
In [3]:
ax = sns.violinplot(x="day", y="total_bill", data=tips)
In [ ]:
 

Thursday, April 23, 2020

reverse the given array in c language

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num, *arr, i;
    scanf("%d", &num);
    arr = (int*) malloc(num * sizeof(int));
    for(i = 0; i < num; i++) {
        scanf("%d", arr + i);
    }


    /* Write the logic to reverse the array. */


    for(i = num-1; i>-1; i--)
        printf("%d ", *(arr + i));
    return 0;
}

output:
  • 6
  • 16 13 7 2 1 12 
  • 
    
  • 
    
  • 12 1 2 7 13 16

how to print the range between two numbers in text format

int main() 
{
    int a, b;
    char *str[] = {"one""two""three""four""five""six""seven",  "eight",  "nine""even""odd"};
    scanf("%d\n%d", &a, &b);
    // Complete the code.
         
  for (int i=a; i<=b; i++) {
    if (i <= 9
         printf ("%s\n", str[i-1]);
    else 
        printf ("%s\n", str[9+(i%2)]);

  }
  return 0;
}

output:
input:
8
11
output:
eight
nine
even
odd

Monday, April 20, 2020

3d plotting for matplot li

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax1 = plt.axes(projection='3d')
a = [4,2,5,7,8,2,9,3,7,8]
b = [5,6,7,8,2,5,6,3,7,2]
c = np.zeros(10)
x = np.ones(10)
y = np.ones(10)
z = [5,3,7,4,8,2,4,8,9,1]
ax1.bar3d(a, b, c, x, y, z, color = 'cyan')
ax1.set_xlabel('x axis')
ax1.set_ylabel('y axis')
ax1.set_zlabel('z axis')
plt.show()
In [ ]:
 
In [ ]:
 

python class topic video