Nov-15-2016, 06:01 PM
First of all, this code won't run (as written), numpy is not capitalized
That aside, you should put print statements into the code until you understand how it all works.
That will help tremendously
Without explanation, here's waht I'm talking about:
That aside, you should put print statements into the code until you understand how it all works.
That will help tremendously
Without explanation, here's waht I'm talking about:
import numpy as N a = N.reshape(N.arange(8), (2,2,2) ) print('a: {}'.format(a)) condition = N.logical_and(a>3, a<6) print('condition: {}'.format(condition)) answer_indices = N.where(condition) print('answer_indices: {}'.format(answer_indices)) answer = (a*2)[answer_indices] print('answer: {}'.format(answer))results:
Output:a: [[[0 1]
[2 3]]
[[4 5]
[6 7]]]
condition: [[[False False]
[False False]]
[[ True True]
[False False]]]
answer_indices: (array([1, 1], dtype=int64), array([0, 0], dtype=int64), array([0, 1], dtype=int64))
answer: [ 8 10]