[SciPy-User] idiom for iterators, expr(T) if isscalar(T) else array([expr(t) for t in T])

denis denis-bz-gg@t-online...
Sun Oct 18 06:34:42 CDT 2009

On Oct 16, 7:10 pm, josef.p...@gmail.com wrote:
> print lerp( np.linspace( .1, .5, 3 ), p0, p1 )
>     # => a nonsense result, with no warning
> This could also be exactly what the user wants, evaluate the function
> at 3 points, taking one value from each array.
> Or, if p0 and p1 are column vectors and t is 1d or row vector, the
> user would get correctly broadcasted values but in row order.

When interpolating colors, you want a color;
in general, you want interpolated.shape == input.shape,
yes assert t is 1d or row.

> A few comments to the broadcasting example:
> I still think that "restrict" is not really the right word in "A way
> to restrict broadcasting in such cases", better would be "to force
> correct broadcasting".
How about "limit" ?  "force" is strong

> To avoid the problem, with 2-dim arguments, I would ravel  t and the p's first

I'm afraid that would increase my (neophyte) FUD, fearUncertaintyand
could there be inputs of shape ... that someday don't work
Better assert or raise NotImplementedError than that !

Do you and other experts have edit-anything rights in
advice.mechanicalkern.com ?
I'd find that good -- fix it once.

  -- denis

More information about the SciPy-User mailing list