Next ❯ ❮ Previous

PYTHON NUMPY OPERATION



 import numpy as np
 a=np.array([10,20,30,40])
 print(a.ndim)      # this ndim represent no. dimension
               #this is one dimension so its output is 1


Output
  1

 import numpy as np
 a=np.array([(10,20,30,40),(50,60,70,80)])
 print(a.ndim)      # this ndim represent no. dimension
               #this is two dimension so its output is 2


Output
  2

 import numpy as np
 a=np.array([10,20,30,40])
 print(a.itemsize)      #10 is having 4byte so it output is 4
              


Output
  4

 import numpy as np
 a=np.array([10,20,30,40])
 print(a.dtype)      # dtype is use for know as datatype
               # so datatype is int32


Output
  int32

 import numpy as np
 a=np.array([10,20,30,40])
 print(a.size)     # size is know to the size of values in this we take four values so output is 4
              

Output
  4

 import numpy as np
 a=np.array([10,20,30,40])
 print(a.shape)     #shape is known to no. of columns
              

Output
  (4,)

 import numpy as np
 a=np.array([(10,20,30,40),(50,60,70,80)])
 print(a.shape)     #in this 2 rows and 4 columns
              

Output
  (2,4)

 import numpy as np
 a=np.array([(10,20,30,40),(50,60,70,80)])     #reshape() is use in to change the rows and columns
 print(a.reshape(4,2))    
              

Output
  -[[10 20]
[30 40]
[50 60]
[70 80]]


 import numpy as np
 a=np.array([(10,20,30,40),(50,60,70,80)])
 print(a[0,2])    # 0 is row no and 2 is index no.
 print(a[0:,2])    # in this we fetch both same index no.


Output
  30
[30 70]

 import numpy as np
 a= np.linspace(1,3,10)
 print(a)    # 0 is row no and 2 is index no.


Output
  [1.     1.22222222 1.44444444 1.66666667 1.88888889 2.1111111
2.33333333 2.55555556 2.77777778 3.     ]

 import numpy as np
 a=np.array([10,20,30,40,50,100])     #reshape() is use in to change the rows and columns
 print(a.min())    
 print(a.max())             
 print(a.sum())

Output
 10
100
250


 import numpy as np
 a=np.array([(10,20,30,40),(50,60,70,80)])     
 print(a.sum(axis=0))     # axis 0 means (10,20,30,40)
 print(a.max())      # axis 1 means (50,60,70,80)       
 print(a.sum())

Output
 [ 60 80 100 120]
[100 260]

 import numpy as np
 a=np.sqrt([(10,20,30,40),(50,60,70,80)])    
 print(a)     


Output
[[3.16227766 4.47213595 5.47722558 6.32455532]
[7.07106781 7.74596669 8.36660027 8.94427191]]

Next ❯ ❮ Previous

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved