Back to all posts

Addition, subtraction, multiplication, and dot product using NumPy in Python:

Here are some examples of addition, subtraction, multiplication, and dot product using NumPy in Python: import numpy as np # Create two arrays a = np.array…



Here are some examples of addition, subtraction, multiplication, and dot product using NumPy in Python:

PHP
import numpy as np

# Create two arrays
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])

# Element-wise addition
c = np.add(a, b)
print(c) # [5 7 9]

# Element-wise subtraction
d = np.subtract(a, b)
print(d) # [-3 -3 -3]
PHP
# Element-wise multiplication
e = np.multiply(a, b)
print(e)  # [ 4 10 18]

# Dot product
f = np.dot(a, b)
print(f) # 32

# Transpose of a matrix
A = np.array([[1, 2], [3, 4]])
D = np.transpose(A)
print(D) # [[1 3]
            [2 4]]

Keep building your data skillset

Explore more SQL, Python, analytics, and engineering tutorials.