python维度切片中三个是怎么取值的_python:在给定维度索引的情况下提取多维数组的一个切片...

您可以使用

slice函数并在运行时使用相应的变量列表调用它,如下所示:

# Store the variables that represent the slice in a list/tuple

# Make a slice with the unzipped tuple using the slice() command

# Use the slice on your array

例:

>>> from numpy import *

>>> a = (1, 2, 3)

>>> b = arange(27).reshape(3, 3, 3)

>>> s = slice(*a)

>>> b[s]

array([[[ 9, 10, 11],

[12, 13, 14],

[15, 16, 17]]])

这与:

>>> b[1:2:3]

array([[[ 9, 10, 11],

[12, 13, 14],

[15, 16, 17]]])

最后,相当于在通常的表示法中没有指定2:之间的任何东西是将None放在你创建的元组中的那些位置.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值