NumPy Tutorial

Random Shuffle and Permutations in NumPy 0

Random Shuffle and Permutations in NumPy

Program 1 # Random Shuffle and Permutations in NumPy #shuffle() and permutation(). import numpy as np from numpy import random # mylist=[’12@56′,’Yu562′,345,’Thg78$’,67.677] # mylist=random.permutation(mylist) # print(mylist[0]) myar=np.array([0,1,1,0]) random.shuffle(myar) #print(myar[0]) if(myar[0]==0): print(“HEAD”) else: print(“TAIL”) #...

Universal Functions in NumPy 0

Universal Functions in NumPy

Program 1 # Universal Functions in Numpy #Universal Functions are NumPy functions that we use on the ndarray object. # Its also know as ufuncs # import numpy as np # ar1=[10,20,30,40,50] # ar2=[1,2,3,4,5]...

Random Distribution in NumPy 0

Random Distribution in NumPy

Program 1 #Random Distribution in Numpy #Random distribution is a set of random numbers that follow a certain probability density function. # Create a 1-D array which contain 50 values, where each value has...

Random Numbers in NumPy 0

Random Numbers in NumPy

Program 1 from numpy import random #Random number #randint() , rand() # How to generate Random Array # How to generate Random number from array using choice() x=random.choice([10,4,6,1,5,8,7,12,10],size=(2,2)) print(x) # myar2=random.randint(1000,size=(2,3,4)) # print(myar2) #...

NumPy Searching and Sorting Arrays 0

NumPy Searching and Sorting Arrays

Program 1 # Searching and Sorting in Numpy import numpy as np # Sorting # ar1=np.array([5,2,6,1,3,4,8,10,9]) # ar1=np.sort(ar1) # print(ar1) # ar1=np.array([[2,5,3],[1,6,5],[7,4,5],[9,5,3]]) # ar1=np.sort(ar1,axis=0) # print(ar1) ar1=np.array([5,2,6,1,3,4,8,10,9]) ar1=np.sort(ar1) print(ar1) x=np.searchsorted(ar1,6) print(x) # Searching #...

NumPy Splitting Array 0

NumPy Splitting Array

Program 1 import numpy as np #split() ,array_split(),hsplit(),vsplit() ar1=np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]) newar=np.vsplit(ar1,2) print(ar1) print(“—————————————-“) print(newar) # hsplit() # ar1=np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]) # print(ar1) # print(“————————————————–“) # newar=np.hsplit(ar1,3) # print(newar) # ar1=np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]) # print(ar1) # print(ar1.shape) # print(“————————————————–“) #...

NumPy Filter Array 0

NumPy Filter Array

Program 1 #Filter import numpy as np myar=[] print(“Enter Percentages of 10 student: “) for i in range(1,11): n=int(input()) myar.append(n) ar=np.array(myar) filt_arr=[] for x in ar: if(x>=60): filt_arr.append(True) else: filt_arr.append(False) newar=ar[filt_arr] print(newar) # myar=[]...

Arithmetic Operations in NumPy 0

Arithmetic Operations in NumPy

Program 1 # Difference between copy and view # digonal function #Arithmetic operations beetween two array import numpy as np # Rules of Arithmetic operations in numpy array # 1. Shape of Arrays must...