考慮以下方便循環成語。返回子陣列
import numpy
print "shape of"
x = numpy.array([['a', 'b'], ['c', 'd']])
print x
print "is", x.shape
for row in x:
print "shape of", row, "is", row.shape
這給
shape of
[['a' 'b']
['c' 'd']]
is (2, 2)
shape of ['a' 'b'] is (2,)
shape of ['c' 'd'] is (2,)
我的問題是,一個可以保存方便for row in x
成語在返回其具有形狀(2,1)的陣列,在這種情況下?謝謝。 將子陣列的形狀從(2,)轉換爲(2,0)的函數會很好。例如。
for row in x:
print "shape of", somefunc(row), "is", row.shape
返回
shape of ['a' 'b'] is (2,1)
@Woltan:對,編輯。謝謝。 –