[SciPy-User] idiom for iterators, expr(T) if isscalar(T) else array([expr(t) for t in T])
denis
denis-bz-gg@t-online...
Thu Oct 15 12:20:23 CDT 2009
On Oct 15, 6:13 pm, josef.p...@gmail.com wrote:
>
> solution: add a new dimension, turn t into a "column vector"
> then each (one element) row of `t` is multiplied with each (one
> element) column of `p`
>
> t[:,None] or t[:, np.newaxis] add a new axis and increase dimension of array
> Josef
Nice, that turns off broadcasting t * p0 etc. which is exactly what's
needed here --
until the evil day when some caller passes in column vecs for p0 etc.
and broadcasting kicks in, wrong.
Is there a general way of turning off broadcasting in particular
functions ?
In interpolation one often has func( t, x ) where t may be a scalar or
range, x anything,
and wants exactly funciter() -- ugly, slow, correct.
Bytheway .../site-packages/numpy/doc/broadcasting.py in the dist has
pretty good examples
More information about the SciPy-User
mailing list