Advanced Array Creation

2. Advanced Array Creation 

We can define the data type of the elements in the numpy array

import numpy as np

array1 = np.array( [ [1,2,3], [4,5,6] ], dtype=complex ) 
 # Here a complex numpy array is created

array2 = np.array( [ [1,2,3], [4,5,6] ], dtype=float )          # Here a float numpy array is created

array3 = np.array([1,0,3,7,1,0,0])
array31 = arr.astype(bool)                                               # Here a boolean numpy array is created
print(newarr)
print(newarr.dtype)          

array4 = np.array( [  ])                         #By default, the dtype of the created empty array is float64

array5 = np.zeros((3,4,4))                   #creates an array full of zeros in dimensions mentioned 

array6 = np.ones( (2,3,4))                   #creates an array full of ones in dimensions mentioned 

array7 =np.empty((3,8))                    # creates an array  initial content is random & value
                                                              # depends on the state of the memory.

# To create sequences of numbers as array 'arange' function is used in Numpy
# First element is starting number and second number is ending (excluding)
# Thrid number is the interval in ellements created

array8 =np.arange( 10, 300, 5 )   # Integer

array9 =np.arange( 0, 10, 0.2 )   # Floating Point

# Function 'linspace' that display the number of elements instead of intervals used in arrange
# First element is starting number and second number is ending (including)
# Thrid number is the number of elements to create array

array10 =np.linspace( 10, 200, 10 )

-------------------------------------------------------------------------------
Table of Content 
--------------------------------------------------------------------------------

No comments: