In the figure, I have a boolean array of the same length of the matrix. I want to calculate the matrix elements which correspond to the boolean array. How do i do this
a: [true, false, true] b: [[1,1,1], [2,2,2], [3,3,3]]]
Say that the elements of the sub array were to be composed
Index is 0 true
: Thus I start at 3 summaries (zero
The index is 1 incorrect
: Thus the conference stays at 3
The index is 2 true
: Thus I Adds the inclusion from 12 to 12
How can I do this (Boolean and part of the equation; I will call each individual sub array Do not need to add)?
You can just type your Boolean array a
to b
, Then the resultant (2, 3)
take the sum of the array: np a = np.array ([true, false, true]) b = np. Array (# [1,1,1], [2,2,2], [3,3,3]] # index rows of B where one is true (the first and third, the line of B) print (b [ A]) # [[1 1 1] # [3 3 3] # Impress printing on all the elements in these lines (B [A]. (SUM)) # 12
It seems that you will benefit from reading.
No comments:
Post a Comment