it probably makes a bit more sense to have the input an optional argument but I don't think its worth it to add a new function for more or less cosmetic reasons. You can still support scalars by ignoring the first argument. Fill value should be fill_value and the default 0 as thats what the current piecewise function returns.
On 13.10.2014 09:56, per.brodtk...@ffi.no wrote: > Ok, I will open a pull request. But before I do so, I would like to know what > kind of pull request to make. > Ideally I think the call signature for piecewise should be like this: > > def piecewise(condlist, funclist, xi=None, fillvalue=numpy.nan, args=(), > **kw): > > or this: > > def piecewise(condlist, funclist, xi=None, args=(), **kw): > > The reason why I think so is that if funclist is a list of scalars then xi is > not needed as input and logically should be placed as an optional third > argument to the function and not as the first as numpy.piecewise currently > does. > > Any of those two call signatures will break with the current one in > numpy.piecewise. > So is this new call signature desirable enough that we want to break > backwards compatibility? > > Or should I just keep the current callsignature: > > def piecewise(xi, condlist, funclist, *args, **kw): > > in the pull request? > > Per A. > > -----Original Message----- > From: numpy-discussion-boun...@scipy.org > [mailto:numpy-discussion-boun...@scipy.org] On Behalf Of Julian Taylor > Sent: 10. oktober 2014 22:31 > To: Discussion of Numerical Python > Subject: Re: [Numpy-discussion] Any interest in a generalized piecewise > function? > > On 10.10.2014 11:34, per.brodtk...@ffi.no wrote: >> I have worked on a generalized piecewise function (genpiecewise) that >> are simpler and more general than the current numpy.piecewise >> implementation. The new generalized piecewise function allows >> functions of the type f(x0, x1,.. , xn) i.e. to have arbitrary number >> of input arguments that are evaluated conditionally. >> >> The generalized piecewise function passes all the tests for >> numpy.piecewise function except the undocumented features of >> numpy.piecewise which allows condlist to be a single bool list/array >> or a single int array. >> > > Hi, > One would think you could already pass two arguments to a function by using a > 2d array but I couldn't get that to work with some short testing. > So this looks like a useful improvement over the current piecewise to me. > > Do you want open a pull request on github to discuss the details? > > It would be good if it can replace the current piecewise as having two > functions which do very similar things is not so nice. > > Cheers, > Julian > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion