You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
arr=np.array([1, 2, 3]) # From listarr=np.zeros((3, 3)) # All zerosarr=np.ones((2, 5, 10), dtype=int) # All ones with dtypearr=np.arange(0, 10, 2) # Range [start, end) with step arr=np.linspace(0, 1, 5) # 5 evenly spaced valuesarr=np.random.random(3, 3) # Random uniform distribution [0, 1)arr=np.random.randn(3, 3) # Random normal distribution (mean = 0, std = 1) arr=np.random.randint( 20, size=(3, 4, 5)) # Random int of specified size
Array Properties
arr.shape# Dimensions (blocks, rows, columns)arr.dtype# Data typearr.size# Total number of elementsarr.ndim# Number of dimensionsarr.nbytes# Memory usage
Indexing & Slicing
arr[0] # First elementarr[1:3] # Elements 1-2arr[:, 0] # All elements of the first columnarr[-1] # Last elementarr[arr>5] # Boolean indexingarr[arr!=5] # Boolean indexing