3 min read•june 24, 2024
is a powerhouse for scientific computing in Python. It provides support for large, multi-dimensional arrays and matrices, enabling fast and efficient operations on datasets. This makes it essential for data science tasks and the foundation for other libraries.
NumPy offers tools for creating and manipulating arrays, from basic indexing to reshaping and joining. It also provides a wide range of mathematical and statistical functions, allowing for efficient data processing and analysis. Understanding these features is crucial for effective data manipulation in Python.
[np.sin()](https://www.fiveableKeyTerm:np.sin())
, [np.exp()](https://www.fiveableKeyTerm:np.exp())
)np.array()
, [np.zeros()](https://www.fiveableKeyTerm:np.zeros())
)np.array()
from a list or tuple
np.zeros()
, [np.ones()](https://www.fiveableKeyTerm:np.ones())
, [np.arange()](https://www.fiveableKeyTerm:np.arange())
)[dtype](https://www.fiveableKeyTerm:dtype)
parameter (np.array([1, 2, 3], dtype=np.float64)
)shape
returns the dimensions of the array as a tuple ((3, 4)
)size
returns the total number of elements in the array (12
)ndim
returns the number of dimensions (axes) of the array (2
)[]
with index or slice notation (arr[0]
, arr[1:5]
)arr[1, 2]
)start:stop:step
syntax (arr[0:6:2]
)arr[[0, 2, 4]]
)reshape()
to change the shape of an array (arr.reshape(2, 6)
)[flatten()](https://www.fiveableKeyTerm:flatten())
or [ravel()](https://www.fiveableKeyTerm:ravel())
(arr.flatten()
)[np.concatenate()](https://www.fiveableKeyTerm:np.concatenate())
, [np.vstack()](https://www.fiveableKeyTerm:np.vstack())
, and [np.hstack()](https://www.fiveableKeyTerm:np.hstack())
(np.concatenate((arr1, arr2))
)[np.split()](https://www.fiveableKeyTerm:np.split())
, [np.vsplit()](https://www.fiveableKeyTerm:np.vsplit())
, and [np.hsplit()](https://www.fiveableKeyTerm:np.hsplit())
(np.split(arr, 3)
)+
, -
, *
, /
, and **
(arr1 + arr2
)[np.sqrt()](https://www.fiveableKeyTerm:np.sqrt())
, np.exp()
, and [np.log()](https://www.fiveableKeyTerm:np.log())
for element-wise computations (np.sqrt(arr)
)np.sin()
, [np.cos()](https://www.fiveableKeyTerm:np.cos())
, and [np.tan()](https://www.fiveableKeyTerm:np.tan())
on arrays (np.sin(arr)
)[np.mean()](https://www.fiveableKeyTerm:np.mean())
, [np.median()](https://www.fiveableKeyTerm:np.median())
, [np.std()](https://www.fiveableKeyTerm:np.std())
, and [np.var()](https://www.fiveableKeyTerm:np.var())
(np.mean(arr)
)[np.min()](https://www.fiveableKeyTerm:np.min())
and [np.max()](https://www.fiveableKeyTerm:np.max())
(np.max(arr)
)[np.sum()](https://www.fiveableKeyTerm:np.sum())
and [np.prod()](https://www.fiveableKeyTerm:np.prod())
(np.sum(arr)
)np.mean(arr, axis=0)
)arr1 + arr2
)>
, <
, ==
, !=
)arr[arr > 5]
)&
, |
, ~
)np.random
module to generate random numbers (np.random.rand(3, 4)
)[np.random.rand()](https://www.fiveableKeyTerm:np.random.rand())
and [np.random.randn()](https://www.fiveableKeyTerm:np.random.randn())
(np.random.randn(5)
)[np.random.randint()](https://www.fiveableKeyTerm:np.random.randint())
(np.random.randint(0, 10, size=(2, 3))
)