10.Subtract every elements in 2D array a2d with 1d array b1d, such that the first row’s elements of a2d subtracts the first element of b1d, the second row’s elements of a2d subtract the second element of b1d and the third row’s elements of a2d subtract the third element of b1d.
a2d = np.array([[10,10,10],[11,11,11],[12,12,12]])
b1d = np.array([2,3,4])
Answer:
Output:
array([[8, 8, 8],
[8, 8, 8],
[8, 8, 8]])
array = [[10, 10, 10],
[11, 11, 11],
[12, 12, 12]]
for_sub = [2, 3, 4]
for i in range(len(array)):
for j in range(len(array[i])):
array[i][j] -= for_sub[i]
print(array)
Comments
Leave a comment