[SciPy-user] single elements and arrays

Gideon Simpson grs2103@columbia....
Mon Jun 30 13:14:06 CDT 2008

foo finds a root where x is a parameter in the equation to be solved.   
If x is an array, I iterate through the elements of the array.


On Jun 30, 2008, at 1:52 PM, Robert Kern wrote:

> On Mon, Jun 30, 2008 at 12:45, Gideon Simpson <grs2103@columbia.edu>  
> wrote:
>> Suppose I have a function foo
>> def foo(x):
>>       blah
>> and i have written foo in a vectorized fashion such that x can be a
>> numpy array of #'s.  But suppose I also want to be able to do
>> foo(5.5)
>> where i am interested in the value at a single point.
>> Is there an easy way to handle both cases?  Should I just not permit
>> this sort of ambiguity (force everything to be an array)?
> It depends. If you are just using ufuncs inside, you don't have to do
> anything. Your function will work just fine with arrays and scalars.
> If you're doing something else, like looking at .shape or using .sum()
> or something, then you might need to actually do something. Exactly
> what depends on the details, though. Can you provide more details
> about what your function does?
> -- 
> Robert Kern
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
> -- Umberto Eco
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

More information about the SciPy-user mailing list