On Tue, Dec 12, 2017 at 6:20 PM Marten van Kerkwijk <
m.h.vankerkw...@gmail.com> wrote:
> The real magic happens when you ducktype, and ensure your function
> works both for arrays and scalars on its own. This is more often
> possible than you might think!
Sadly, this still doesn't work in a
The different approaches and corresponding "code bloat" here is one of the
most annoying things I have found about using numpy+scipy. Furthermore, the
flip side to the handling of the inputs, including both type and shape, is
getting the output to match the input, including both type and shape.
On Wed, Dec 13, 2017 at 4:50 AM, Joe wrote:
>
> Hi,
>
> the best example I found was this one:
>
> https://stackoverflow.com/a/29319864/7919597
>
> def func_for_scalars_or_vectors(x):
> x = np.asarray(x)
> scalar_input = False
> if x.ndim == 0:
> x =
Hi,
the best example I found was this one:
https://stackoverflow.com/a/29319864/7919597
def func_for_scalars_or_vectors(x):
x = np.asarray(x)
scalar_input = False
if x.ndim == 0:
x = x[None] # Makes x 1D
scalar_input = True
# The magic happens here
if