I'm coming from a MATLAB background and I'm trying to write this in python/numpy:
[l, m, n] = ndgrid(1:size(dct, 1), 1:size(dct, 2), 1:size(dct, 3));
mycell{i, j} = dct(...
min.^2 <= l.^2 + m.^2 + n.^2 & ...
l.^2 + m.^2 + n.^2 <= max.^2)';
So what the code is supposed to to is take all the values of the array that have an index (e.g. x,y,z) that have a 2-norm between min
and max
, i.e. min^2 < x^2 + y^2 + z^2 < max^2
The only thing I could find was about indexing some values of an array with a condition of the value of the array at this index, however I want to index with a condition on the index itself.
I read about broadcasting and the ix_
function and advanced indexing, however i cannot fit the pieces together.