简体   繁体   中英

Python multi-dimensional notation transpose automatically

I have the following minimal example:

a = np.zeros((5,5,5))
a[1,1,:] = [1,1,1,1,1]
print(a[1,:,range(4)])

This is an example of mixed basic and advanced indexing, as discussed in https:\/\/docs.scipy.org\/doc\/numpy\/reference\/arrays.indexing.html#combining-advanced-and-basic-indexing<\/a>

It's been discussed in previous SO questions and one or more bug\/issues.

In [215]: a[1,:,range(4)].shape
Out[215]: (4, 5)               # slice dimension last
In [216]: a[1,:,:4].shape
Out[216]: (5, 4)
In [219]: a[1][:,[0,1,3]].shape
Out[219]: (5, 3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM