[Numpy-discussion] Generically Creating Views of Equal Dimensions

Alexander Michael lxander.m at gmail.com
Tue Apr 15 10:54:05 EDT 2008


Is there an already existing method to create views that add as many
dimensions as required to bring a collection of arrays to the same
dimensionality by adding the appropriate number of numpy.newaxis's to
the ends? For example:

In [1]: a = numpy.array([1, 2, 3, 4])
In [2]: b = numpy.array([[1,10], [1,10], [1,10], [1,10]])

In [3]: a_,b_ = dimensionalize(a,b) # returns a[:,numpy.newaxis],b
In [4]: a_*b_
array([[ 1, 10],
       [ 2, 20],
       [ 3, 30],
       [ 4, 40]])

Or perhaps there is better way to do the same thing.

Thanks,
Alex



More information about the NumPy-Discussion mailing list