arr=np.arange(0,5)
print(arr) -> [0 1 2 3 4]
print(arr - arr) -> [0 0 0 0 0]
print(arr - 1) -> [-1 0 1 2 3]
np.sqrt(arr) ## take squareroot of array
np.zeros(10) #create array of 10 zeros
np.ones(10) #create array of 10 ones
np.ones(10)*5 #create array of 10 fives
np.zeros(10)+5 #create array of 10 fives
np.arange(10,51) #create np array from 10 to 50
np.arange(10,51,2) #create np array from 10 to 50 with step size 2(even numbers)
np.arange(9).reshape(3,3) #create 3x3 matrix with values from 0-8
np.eye(3) #create 3x3 identy matrix
np.random.rand(1) #generate random number between 0-1
np.random.randn(25) # generate array of 25 random number from standard normal distribution
# create matrix 10 by 10 of 20 linearly spaced points between 0 and 1
np.arange(1,101).reshape(10,10)/100
or
np.linspace(0.01,1,100).reshape(10,10)
# create an array of 20 linearly spaced points between 0 and 1
np.linspace(0,1,20)
#get sum of element of matrix
np.sum(matName) OR
matName.sum()
#get standard deviation of matrix
mat.std()
# get sum of all columns in mat
mat.sum(axis=0)
No comments:
Post a Comment