October 2019
Beginner to intermediate
674 pages
16h 43m
English
NumPy is highly efficient in performance as it works based on vectorized operations, where the need for loops is avoided and the process becomes several times faster. All basic arithmetic operations involving +, -, *, and / take place elementwise and are vectorized:
# Arithmetic operation on arrays with scalarsIn [71]: array_1 = np.array([[1, 2, 3], [4, 5, 6]])In [72]: array_1Out[72]:array([[1, 2, 3],[4, 5, 6]])In [73]: array_1 + 5Out[73]:array([[ 6, 7, 8],[ 9, 10, 11]])In [74]: array_1 * 5Out[74]:array([[ 5, 10, 15],[20, 25, 30]])In [75]: array_1 ** 2Out[75]:array([[ 1, 4, 9],[16, 25, 36]], dtype=int32)
Operations involving two arrays, such as adding or multiplying two arrays, also takes place in a vectorized manner:
# Element-wise ...
Read now
Unlock full access