Jul 30, 2024
import numpy as np
.pip install numpy
or pip3 install numpy
.np.array([1, 2, 3])
.np.array([[1.1, 2.2], [3.3, 4.4]])
.a.ndim
, a.shape
, a.dtype
, a.itemsize
.array[row, column]
.array[:, 0:2]
.array[row, col] = value
.np.zeros((shape))
.np.ones((shape))
.np.full((shape), value)
.np.identity(n)
.np.random.rand(shape)
, np.random.randint(low, high, size)
.np.repeat(array, repetitions, axis)
.array.copy()
to avoid inadvertent modifications.b = a.copy()
.array + 2
, array * 2
.np.sin(array)
for mathematical operations.np.matmul(a, b)
for matrix multiplication.np.linalg
.np.min(array)
, np.max(array)
, with axis parameter for row/column-wise operations.np.sum(array)
.array.reshape(new_shape)
to change array dimensions.np.vstack((array1, array2))
.np.hstack((array1, array2))
.np.genfromtxt('file.txt', delimiter=',')
to load data from a text file.data.astype(np.int32)
.array[array > 50]
.