[SciPy-User] idiom for iterators, expr(T) if isscalar(T) else array([expr(t) for t in T])
Fri Oct 16 12:10:06 CDT 2009
On Fri, Oct 16, 2009 at 12:12 PM, denis <firstname.lastname@example.org> wrote:
> Thanks Josef,
> I've summarized this Q+A in http://advice.mechanicalkern.com
> of course, please edit it if you like.
> (That looks like a good place for such Q+A s, or
> http://stackoverflow.com/questions/tagged/scipy ?
> a separate discussion).
> -- denis
One problem with doing the broadcasting for the user, is that it is
not always clear what the intention of the user is, although it might
be very suggestive from the context.
In your example:
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.
I like your penalized least squares problem (more general than Ridge Regression)
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
To avoid the problem, with 2-dim arguments, I would ravel t and the p's first
Your scalar check doesn't check the dimension of p1.
Thanks for contributing to the docs.
More information about the SciPy-User