Consider the following convenient looping idiom.
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
This gives
shape of
[['a' 'b']
['c' 'd']]
is (2, 2)
shape of ['a' 'b'] is (2,)
shape of ['c' 'd'] is (2,)
My question is, can one preserve the convenient for row in x idiom while returning arrays which have shape (2,1), in this case? Thanks.
A function which converts the shape of the subarray from (2,) to (2,0) would be fine. E.g.
for row in x:
print "shape of", somefunc(row), "is", row.shape
returning
shape of ['a' 'b'] is (2,1)