Numpy: Create a blank and empty array

20 August 2020

Code

Blank array:

# Import library
import numpy as np

# Create blank array
x = np.array([])

# Output
print(x)
print(type(x))
print('Size:', np.size(x))
[]
<class 'numpy.ndarray'>
Size: 0

.

Empty blank array:

Note: An empty array is not empty. In example below, (0) is used to create blank.

# Import library
import numpy as np

# Create blank array 
x = np.empty(0)

# Output
print(x)
print(type(x))
print('Size:', np.size(x))
[]
<class 'numpy.ndarray'>
Size: 0

.

Empty not blank array:

Note: An empty array is not empty. It has random values as shown below. The size of an array may be specified.

# Import library
import numpy as np

# Create empty array of size (2,2)
x = np.empty((2,2))

# Output
print(x)
print(type(x))
print('Size:', np.size(x))
[[ 2.40195438 -0.44702659]
 [-1.31738935 -1.09601137]]
<class 'numpy.ndarray'>
Size: 4






Any errors in code above?
Please send a message.