N-dimensional array
Create
- np.array()
a = np.array([[1,2], [3,4]])
- numpy.ones
create array which has all components 1
np.ones((2, 3)) # [[1., 1., 1.], # [1., 1., 1.]]
- numpy.full()
np.full((2, 3), 7) # [[7, 7, 7], [7, 7, 7]]
- numpy.zeros_like()
a = np.array([[1,2], [3,4]]) np.zeros_like(a) # [[0, 0], [0, 0]]
- np.arange()
like range function, define size of the step
np.arange(0, 10, 2) # [0, 2, 4, 6, 8]
- numpy.empty()
np.empty((2, 3)) # [[?, ?, ?], [?, ?, ?]] # arbitrary values
- np.linspace
Number of samples
np.linspace(0, 10, 5) # [0., 2.5, 5., 7.5, 10.]
- np.eye()
return 2D identity matrix with size N
np.eye(3) # [[1,0,0], [0,1,0], [0,0,1]]
Basic
- numpy ndarray.shape
- np.min(arr, axis)
- np.max(arr, axis)
- np.sum(arr, axis)
np.isnan
np.isclose- Floating Point approximation
np.nan== x, np.nan == np.nan is False
Dimension
np.array([[1,2,3], [4,5,6]]).flatten() # all dimension to 1 dimension # [[1,2,3], → [1,2,3,4,5,6] # [4,5,6]]
- numpy ndarray.transpose()
(new axis order)
(2,3,4) → arr.transpose(1,0,2) → (3,2,4)
Condition
- np.nonzero() - array of non-zero indices
- np.where(condition, if yes value, if no value)
- np.where(condition) - array of true indices
np.where
rng = np.random.RandomState(seed)- rng.randint(low, high, size)
- np.bincount() -
count occurrences of non-negative integers - if negatives are there, ValueError

Seonglae Cho![[numpy 기초] np.linspace와 np.arange의 차이(번역)](https://images.velog.io/velog.png)