I would like to get a matrix of values given two ndarray
's from a ufunc
, for example:
degs = numpy.array(range(5))
pnts = numpy.array([0.0, 0.1, 0.2])
values = scipy.special.eval_chebyt(degs, pnts)
The above code doesn't work (it gives a ValueError
because it tries to broadcast two arrays and fails since they have different shapes: (5,) and (3,)); I would like to get a matrix of values with rows corresponding to degrees and columns to points at which polynomials are evaluated (or vice versa, it doesn't matter).
Currently my workaround is simply to use for
-loop:
values = numpy.zeros((5,3))
for j in range(5):
values[j] = scipy.special.eval_chebyt(j, pnts)
Is there a way to do that? In general, how would you let a ufunc
know you want an n
-dimensional array if you have n
array_like arguments?
I know about numpy.vectorize
, but that seems neither faster nor more elegant than just a simple for
-loop (and I'm not even sure you can apply it to an existent ufunc
).
UPDATE What about ufunc
's that receive 3 or more parameters? trying outer
method gives a ValueError: outer product only supported for binary functions
. For example, scipy.special.eval_jacobi
.