以下の便利なループイディオムを考えてみましょう。この場合には、形状(2,1)を持つ配列を戻しながらnumpy配列をループするときに同じ次元のサブ配列を返す
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
これは、1つの便利なfor row in x
イディオムを保存することができ、
shape of
[['a' 'b']
['c' 'd']]
is (2, 2)
shape of ['a' 'b'] is (2,)
shape of ['c' 'd'] is (2,)
私の質問はできますか?ありがとう。 サブアレイの形状を(2、)から(2,0)に変換する関数は問題ありません。例えば。私はあなたがそれを望む理由は表示されませんが、あなたはこの試み与える可能性
shape of ['a' 'b'] is (2,1)
@Woltan:右、編集しました。ありがとう。 –