Generally, NumPy arrays are more efficient than lists. One reason is that they allow you to do element-wise operations. An element-wise operation allows you to quickly perform an operation, such as addition, on each element in an array.
Multiple arrays can also be used in arithmetic operations, provided that they have the same lengths. When adding or subtracting arrays in NumPy, each element will be added/subtracted to its matching element.
NumPy Arrays support element-wise logical operations, returning new Arrays populated with False or True based on their evaluation.
>>> a = np.array([10,2,2,4,5,3,9,8,9,7])>>> a >5array([True,False,False,False,False,False,True,True,True,True],dtype=bool)
Element-wise Functions in NumPy
abs, fabs Compute the absolute value element-wise for integer, floating point, or complex values. Use fabs as a faster alternative for non-complex-valued data
sqrt Compute the square root of each element. Equivalent to arr ** 0.5
square Compute the square of each element. Equivalent to arr ** 2
exp Compute the exponent ex of each element
log, log10, log2, log1p Natural logarithm (base e), log base 10, log base 2, and log(1 + x), respectively
sign Compute the sign of each element: 1 (positive), 0 (zero), or -1 (negative)
ceil Compute the ceiling of each element, i.e. the smallest integer greater than or equal to each element
floor Compute the floor of each element, i.e. the largest integer less than or equal to each element
rint Round elements to the nearest integer, preserving the dtype
modf Return fractional and integral parts of array as separate array
isnan Return boolean array indicating whether each value is NaN (Not a Number)
isfinite, isinf Return boolean array indicating whether each element is finite (non-inf, non-NaN) or infinite, respectively
cos, cosh, sin, sinh, tan, tanh Regular and hyperbolic trigonometric functions