Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

python - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

[index[0], slice(None), index[1], index[2]]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...