In python if a define:
a = arange(9).reshape(3,3)
as a 3x3 matrix and iterate:
for i in a:
It'll iterate over the matrix's rows. Is there any way to iterate over columns?
In python if a define:
a = arange(9).reshape(3,3)
as a 3x3 matrix and iterate:
for i in a:
It'll iterate over the matrix's rows. Is there any way to iterate over columns?
Assuming that
a
is a well formed matrix, you could try something like:How about
or, shorter:
This may look expensive but is in fact very cheap (it returns a view onto the same data, but with the shape and stride attributes permuted).