python - 在python中添加多个切片
问题描述
我想在单个数组中获取x[start1:stop1:step1 ]
and 的切片。x[start2:stop2:step2]
Python中是否有这样的语法:
x[start1:stop1:step1 + start2:stop2:step2]
在 Matlab 中很简单:
x(start1:step1:stop1 start2:step2:stop2)
更新:
我看到很多答案都建议串联。
我最初的目标是为更高维数组做切片,例如在 2D 中:
x[start1:stop1 + start2:stop2, start3:stop3 + start4:stop4]
串联没问题。但是在高维度上它似乎太复杂了。
有没有像matlab一样简单的方法?
x(start1:stop1 start2:stop2, start3:stop3 start4:stop4 )
我们可以连接数组索引,而不是数组本身吗?
解决方案
您可以像这样连接两个数组(列表):x[start1:stop1:step1] + x[start2:stop2:step2]
推荐阅读
- javascript - 表单提交后如何打开模式
- eclipse - 如何在eclipse中关闭jsp文件的断线
- css - Bootstrap 4 - 带标签的模态标题 - 如何降低标题高度
- java - 具有复合主键的地图上的休眠 HQL 查询
- java - 如果不将行转换为字符串,代码可以正常工作吗?
- swift - 范围内的 Swift 变异数据
- eclipse - Eclipse 中是否有一个快捷键可以将光标放在下一个突出显示的选择处?
- hive - Hive - 按数据内容对外部表进行分区
- json - 使用 JSONPath 按名称过滤 json 属性
- javascript - 在画布html5中添加自定义动画