import numpy as np
a = np.array([[1,2,3],[2,3,4]])print(f'a.ndim={a.ndim}')print(f'a.shape={a.shape}')print(f'a.size={a.size}')print(f'a.dtype={a.dtype}')print(f'a.itemsize={a.itemsize}')# the size in bytes of each element of the array. print(f'a.data={a.data}')# the buffer containing the actual elements of the array.
np.zeros((3,4))
np.ones((3,4),dtype = np.int16)# default type is float64
np.arange(0,2,0.3)from numpy import pi
x = np.linspace(0,2* pi,100)# useful to evaluate function at lots of points
f = np.sin(x)# 9 numbers from 0 to 2
c = np.arange(24).reshape(2,3,4)
Basic Operations
b**210* np.sin(a)
a <35
a.sum()
a.min()
a.max()
b.sum(axis=0)# sum of each column
b.min(axis=1)# min of each row
b.cumsum(axis=1)# cumulative sum along each row
A = np.array([[1,1],[0,1]])
B = np.array([[2,0],[3,4]])
A * B # elementwise product
A @ B # matrix product
A.dot(B)# matrix product