Numpy Ndarray Operation

A PHP Error was encountered

Severity: Warning

Message: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.

Filename: blog/post_details.php

Line Number: 38

Backtrace:

File: /home/solutio1/public_html/application/views/blog/post_details.php
Line: 38
Function: strtotime

File: /home/solutio1/public_html/application/controllers/Blog.php
Line: 14
Function: view

File: /home/solutio1/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.

Filename: blog/post_details.php

Line Number: 38

Backtrace:

File: /home/solutio1/public_html/application/views/blog/post_details.php
Line: 38
Function: date

File: /home/solutio1/public_html/application/controllers/Blog.php
Line: 14
Function: view

File: /home/solutio1/public_html/index.php
Line: 315
Function: require_once

2019-08-19
Omsingh Bais

Numpy Ndarray Operation

 

In last article we learnd about the basic of Numpy array and creation of ndarray object. In this article we are going to learn about the various operation on ndarray.

If you are new to numpy array then check previous article 

Follwing is the operation that can be performed on ndarray :

  • Creating empty array :

 import numpy as np

 x = np.array([ ]) # array creation using list
 y = np.array(( )) # array creation using tuples
 z = np.array({ }) # array creation using dictionary
 print (x)
 print (y)
 print (z)

Output :

 []
 []
 {}

 

  • Creating one dimensions array

 import numpy as np

 x = np.array([1,2,3]) # array creation using list
 y = np.array((4,5,6 )) # array creation using tuples
 z = np.array({'Name': 'solutionstouch', 'Founded': 2019}) #array creation using dictionary
 print (x)
 print (y)
 print (z)

 

Output: 

 [1 2 3]
 [4 5 6]
 {'Founded': 2019, 'Name': 'solutionstouch'}

 

  • Creating 2-dimensions array

 import numpy as np

 x = np.array([[1,2],[3,4]]) # array creation using list
 y = np.array(((5,6),(7,8))) # array creation using tuples
 z = np.array({'Name': 'solutionstouch', 'Founded': 2019}) #array creation using dictionary
 print (x)
 print (y)
 print (z)

Output :

 [[1 2]
  [3 4]]
 [[5 6]
  [7 8]]
 {'Founded': 2019, 'Name': 'solutionstouch'}

 

  • Creating ndarray with dtype parameter :

 import numpy as np
 x = np.array([11, 25, 68], dtype = float) # Float datatype
 y = np.array([11, 25, 68], dtype = complex) # Complex datatype
 z = np.array([11.0, 25.0, 68.0], dtype = int) # integer datatype

 print (x)
 print (y)
 print (z)

Output :

 [ 11. 25. 68.]
 [ 11.+0.j 25.+0.j 68.+0.j]
 [11 25 68]

 

  •  Creating ndarray with the use of copy parameter

Copy parameter Return an array copy of the given object.

 import numpy as np
 x = np.array([11, 22, 33]) #create an array.
 y = x #y is a reference variable
 z = np.copy(x) #copy of a x save in z

 x[0] = 10
 print(x[0] == y[0]) # output will be True
 print(x[0] == z[0]) # Output will be False because z having the initial value of x

 

Output:

 True
 False

 

  • Creating ndarray with the use of ndmin parameter

Ndmin means minimum dimensions of the resulting array.

 import numpy as np
 x = np.array([11,22,33,44], ndmin = 2) #ndmin is 2
 y = np.array([11,22,33,44], ndmin = 4) #ndmin is 4
 z = np.array([11,22,33,44], ndmin = 6) #ndmin is 6
 print(x)
 print(y)
 print(z)

 

Output: 

 [[11 22 33 44]]
 [[[[11 22 33 44]]]]
 [[[[[[11 22 33 44]]]]]]

 

Happy coding.....

 

 

 

 


About author

Card image cap
Omsingh Bais

Having more than 1+ year experience in the data scientist domain.!

-Data Scientist

0 Comments