[SciPy-user] single elements and arrays
Mon Jun 30 12:52:20 CDT 2008
On Mon, Jun 30, 2008 at 12:45, Gideon Simpson <email@example.com> wrote:
> Suppose I have a function foo
> def foo(x):
> 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
> 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?
"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
More information about the SciPy-user