ndarray n-dimensional array
1
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)
Execution result of 1
[[1 2 3]
[4 5 6]]
You can specify the data type of the array. How many bits of type should be used? You can adjust the amount of memory to be secured by specifying the number of bits.
2
import numpy as np
a = [1, 2, 3]
ndarray = np.array(a, dtype='float32')
print(ndarray.dtype)
ndarray = np.array(a, dtype='int32')
print(ndarray.dtype)
Execution result of 2
float32
int16
Change data type
3
import numpy as np
a = [1, 2, 3]
arr = np.array(a, dtype='int32')
arr2 = arr.astype('float32')
print(arr2.dtype)
Execution result of 2
float32
Recommended Posts