如何从numpy ndarray中的每个维度获取第一个元素?
import numpy
A = numpy.array([['a','b','c'],['d','e','f'],['g','h','i']])
结果应该是:
Result = ['a','d','g']
答案 0 :(得分:4)
>>> import numpy
>>> A = numpy.array([['a','b','c'],['d','e','f'],['g','h','i']])
>>> A[:,0]
array(['a', 'd', 'g'],
dtype='|S1')
>>> A[...,0]
array(['a', 'd', 'g'],
dtype='|S1')
答案 1 :(得分:2)
答案 2 :(得分:1)
使用拍摄功能
import numpy
A = numpy.array([['a','b','c'],['d','e','f'],['g','h','i']])
print A.take((0,), 1)