Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个格式为 numpy 的数组:
a = [[1,2,3],[4,5,6],[7,8,9]]
我想将元素提取为:
a' = [[1,2],[4,5],[7,8]]
我尝试使用:
a' = a[:][:2]
但它不像我预期的那样工作
>>> [l[:2] for l in a] [[1, 2], [4, 5], [7, 8]]
>>> numpy.array([[1,2,3],[4,5,6],[7,8,9]])[:,:2] array([[1, 2], [4, 5], [7, 8]])