最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - NumPy 2D indexing using different slice per column - Stack Overflow

programmeradmin5浏览0评论
import numpy as np

x = np.arange(12).reshape(3, 4)
print(x)

idx = np.array([0, 1])
y = x[:2, idx : idx + 2]

# should be
# [[0 1]
#  [5 6]]

So I want to get different slice for each row. In this example, it's the 0, 1 indexes from the first row and 1, 2 indexes from the second row.

Instead, I'm getting:

TypeError: only integer scalar arrays can be converted to a scalar index

What are my options? Are there more than one? Any performance implications?

发布评论

评论列表(0)

  1. 暂无评论