Numpy - operations

import numpy as np

a = np.array([1, 2, 3])

b = np.array([5, 6, 7])

1) Performs element-wise operations

print(a + 2)

print(a 3)*

print(a ** 2)

print(a / 2)

print(a % 2)

print(a + b)

[3 4 5]
[3 6 9]
[1 4 9]
[0.5 1.  1.5]
[1 0 1]
[ 6  8 10]

Note: in case of (a + b) -> both must be of the same dimensions or will throw an error

2) Some common built-in functions

print(a.mean())

print(b.sum())

/ Dot operation

a1_2d = np.array([[1, 2], [3, 4]])

a2_2d = np.array([[10, 20], [30, 40]])

a1_2d.dot(a2_2d)


2.0
18
array([[ 70, 100],
       [150, 220]])

Note: there are a lot more other built-in functions but these two are the most used