Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array Assignment in numpy / : colon equivalent

I am trying to relate the python/numpy indices of two arrays with different sizes, but I cannot pass index one from the small array to the large array through a subroutine.

For example, I have two numpy arrays: a1 and a2. a1.shape = (240,33,258) and a2.shape = (240,40,33,258). I am finding indices in a1 and relating these indices to a2. ie., index1 = numpy.where(a > n). I can grab the data that I an interested in using

dat1 = a1[index]
dat2 = a2[index[0],:,index[1],index[2]]

with the resulting dat shapes as dat1.shape = (n) and dat2.shape = (n, 40). To speed up the program, I want to pass the index through a subroutine, but I cannot pass [index[0],:,index[1],index[2]] through a subroutine because I cannot pass the colon ':'.

I believe my solution would be to pass the numerical equivalent to ':' in the subroutine, but I have not found an answer.

Any help?

Thank you very much

like image 879
NPB Avatar asked Feb 23 '23 16:02

NPB


1 Answers

You should be able to use slice(None) to represent :. As in

[index[0], slice(None), index[1], index[2]]
like image 156
donkopotamus Avatar answered Mar 03 '23 21:03

donkopotamus