Answer to Question #314312 in Python for xxx

Question #314312

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]])


1
Expert's answer
2022-03-20T06:20:54-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS