#numpy
import numpy as np
#making array from list
a = np.array([2,3,4])
a
#using arange function in np same as range function
a = np.arange(1,13,2)
a
#linspace takes 3 values start,end, number of items
a = np.linspace(1,12,6)
a
#changing the dimension of array
a = a.reshape(3,2)
a
#number of elements in array
a.size
#get shape of array
a.shape
#(3,2) represents 3 X 2 matrix
#datatype
a.dtype
#memory each item takes in array
a.itemsize
#creating multi dimension array
b = np.array([(1.5,2,3), (4,5,6)])
b
a
#comparing each element of array
a < 7
#multiplying each element by 3
a * 3
#in list we have to write a for loop and multiply each element by 3.
#creating empty array of zeroes
np.zeros((3,4))
#creating arrays of 1
np.ones((2,3))
#passing datatype
np.ones(10, dtype=np.int16)
#this will set decimal point to 2 places and won't show scientific notation and will be activate till it is not changed again
np.set_printoptions(precision=2, suppress=True)
#creating array of random values ranging 0 to 1
a=np.random.random((2,3))
a
#random integer from 0 to 10 creating 5 values
a=np.random.randint(0,10,5)
a
#getting sum of arrays
a.sum()
#getting max
a.max()
#getting min
a.min()
#getting mean
a.mean()
#getting variance
a.var()
#getting standand deviations
a.std()
a = np.random.randint(1,10,6)
a
a = a.reshape(3,2)
a
#sum of horizontal axis
a.sum(axis=1) #7+5, #7+7, #9+6
#sum of vertical axis
a.sum(axis=0) #7+7+9 and 5+7+6
a = np.arange(10)
a
#works inplace like sort, shuffles the array
np.random.shuffle(a)
a
#get a random element from array
np.random.choice(a)
np.random.choice(a)
#sorting array elements
np.sort(a)
#loading file in numpy
data = np.loadtxt("data.txt", dtype=np.uint8, delimiter=",", skiprows=1)
#skiprows skip the first line which is header in this case