Numpy Interview Questions 20
Numpy Interview Questions 20
1. What is NumPy?
NumPy (Numerical Python) is a library for numerical computing in Python, providing support for
multi-dimensional arrays and efficient mathematical operations.
NumPy arrays are more efficient, consuming less memory and enabling faster operations due to
their fixed data types and support for vectorized operations.
NumPy uses `np.nan` (Not a Number) to represent missing values in floating-point arrays.
`np.where(condition, x, y)` returns elements from `x` where the condition is True, otherwise from `y`.
It is used for conditional array operations.
Using `np.concatenate((arr1, arr2), axis)`, where `axis=0` joins along rows, and `axis=1` joins along
columns.
Ufuncs are optimized functions for element-wise operations, such as `np.add()`, `np.subtract()`,
`np.multiply()`, and `np.exp()`.
Using `np.sort(array)`, which returns a sorted copy of the array. Use `axis` parameter to sort along
specific dimensions.
`np.unique(array)` returns the sorted unique values in an array, useful for removing duplicates.
Masked arrays handle missing or invalid data by marking certain values as 'masked', preventing
them from affecting calculations. Created using `np.ma.array()`.