# Element-wise addition with lists
x = [1, 2, 3]
y = [4, 5, 6]
z = [a + b for a, b in zip(x, y)]
print(z)
[5, 7, 9]
Arewa Data Science Academy
By the end of this lecture, you will:
# Element-wise addition with lists
x = [1, 2, 3]
y = [4, 5, 6]
z = [a + b for a, b in zip(x, y)]
print(z)
[5, 7, 9]
print(f"using np.array: {np.array([1, 2, 3])}")
print(f"Initiating using np.zeros: {np.zeros((2, 3))}")
print(f"using np.ones: {np.ones(5)}")
print(f"Initiating an identity matrix: {np.eye(3)}")
print(f"using np.arange: {np.arange(0, 10, 2)}")
print(f"using np.linspace: {np.linspace(0, 1, 5)}")
using np.array: [1 2 3]
Initiating using np.zeros: [[0. 0. 0.]
[0. 0. 0.]]
using np.ones: [1. 1. 1. 1. 1.]
Initiating an identity matrix: [[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
using np.arange: [0 2 4 6 8]
using np.linspace: [0. 0.25 0.5 0.75 1. ]
Ask away or let’s do a few exercises together!