[Numpy-discussion] broacasting question

Thomas K Gamble tkgamble at windstream.net
Fri Jul 1 08:41:57 EDT 2011


> 
> Right, I forgot to point out that there are at least 2 ways to bring the
> arrays into compatible shapes (that's the reason broadcasting does not
> work here, because numpy only does automatic broadcasting if there is an
> unambiguous way to do so). So the IDL arrays being Fortran-ordered is the
> essential bit of information here. Just two remarks:
> I. Assigning a = reshape(b.flatten('F')[:size(c)]/c.flatten('F'), c.shape,
> order='F') as above will create a new array of shape c.shape - if you
> wanted to put your results into an existing array of shape(2048,3577),
> you'd still have to explicitly say a[:,:3136] = ... II. The flatten()

That was the error in my example I refered to.

> operations and the assignment above all create full copies of the arrays,
> thus the np.add ufunc above together with simple reshape operations might
> improve performance somewhat - however keeping the Fortran order also
> requires some costly transpositions, as for your last example
> 
> a = np.divide(b.T[:3136].reshape(c.T.shape).T, c, out=a)
> 
> so YMMV...
> 
> Cheers,
> 						Derek
> 
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
--
Thomas K. Gamble tkgamble at windstream.net
The fruit of the righteous is a tree of life; and he who wins souls is wise. 
(Proverbs 11:30)



More information about the NumPy-Discussion mailing list