Numpy universal functions are "vectorized" functions operating on elements (element by element) on a Numpy array.
Questions tagged [numpy-ufunc]
198 questions
1
vote
2 answers
Documenting first-class-assigned functions
I have a function defined by making use of the first-class nature of Python functions, as follows:
add_relative = np.frompyfunc(lambda a, b: (1 + a) * (1 + b) - 1, 2, 1)
Either I need a way to add a docstring to the function defined as it is, or…

Sam
- 222
- 2
- 12
1
vote
0 answers
Python Sympy ufuncify FallingFactorial
I want to ufuncify Sympy's FallingFactorial function so that it works similar to numpy on array inputs instead of just a pair of integers.
I tried the following code:
from sympy.functions.combinatorial.factorials import FallingFactorial
from…

sambajetson
- 193
- 1
- 9
1
vote
1 answer
polyfit with multi-dimensional x coordinate
Suppose that I have a (400,10) array called x and a (400,10) array called y. Is that possible to do a polyfit of each row in y to the corresponding row in x without iteration? If with for loop it will be something like
import numpy as np
coe =…

lelouchkako
- 123
- 1
- 7
1
vote
1 answer
make np.vectorize return scalar value on scalar input
The following code returns an array instead of expected float value.
def f(x):
return x+1
f = np.vectorize(f, otypes=[np.float])
>>> f(10.5)
array(11.5)
Is there a way to force it return simple scalar value if the input is scalar and not the…

tal
- 860
- 7
- 19
1
vote
1 answer
Why can't I use numpy.logaddexp.reduce?
Why can't I use numpy.logaddexp.reduce?
In [46]: a = np.array([1,5, 3, 2])
In [47]: np.logaddexp.reduce(a)
---------------------------------------------------------------------------
TypeError Traceback (most recent…

Neil G
- 32,138
- 39
- 156
- 257
0
votes
1 answer
Numba GuFunc giving incorrect output
I have a python function that follows:
@njit(cache=True, fastmath=True, parallel=True)
def min_var_opt(covariance_matrix: np.ndarray) -> np.array:
n = covariance_matrix.shape[0]
# Compute the inverse of the covariance…

user3299166
- 169
- 1
- 13
0
votes
0 answers
How can I have a Cython function in a class exposed as ufunc while retaining fast version for use in Cython?
I want to have a Cython function in a class, and exposure a ufunc version of it to Python, while keeping the fast scaler version for use in Cython. My current attempt to do this gives me (nearly) what I want, however means I have to write 4 versions…

hbwales
- 158
- 5
0
votes
2 answers
How to efficiently apply a function to a NumPy array view in-place?
I have a view of a NumPy array. I want to apply a function to each of its elements and save the result into said view (essentially, I want to do an in-place map). I do not want to use for loops, because they do not benefit from any NumPy…

sajmon
- 131
- 6
0
votes
0 answers
how to optimize np.linalg.norm?
I have the following function to compute distance between two points that are represented by matrices. i.e. points is a list of matrices, and other_points is an array of matrices.
def find_dist(points: list, other_points: np.array,) -> int:
…

vm finance
- 1
- 1
0
votes
1 answer
"TypeError: return arrays must be of ArrayType" even though all input arrays have the same type
I'm trying to create a piece of software that calculates the density distribution inside a white dwarf by dividing it into a bunch of layers and running a crude physics simulation on them. I wrote some functions that I tried to vectorize, but I keep…

zucculent
- 123
- 6
0
votes
0 answers
Why does NaN-comparisons warn only inside np.frompyfunc?
If you compare np.nan to some other value and you do it in a np.frompyfunc, will raise a warning. Why is this? Is it a bug or a feature?
import numpy as np
func = np.frompyfunc(lambda x: x<0,nin=1,nout=1)
print(func(1)) # False, no…

LudvigH
- 3,662
- 5
- 31
- 49
0
votes
1 answer
Numpy function/method to calculate moving range?
Want to calculate moving range in numpy.
Wrote function using Pandas, want simple/fast way to return numpy array with equivalent values. Don't need the name of new array, just the values.
def get_moving_range(my_series, na_replace_value=None):
…

Programming_Learner_DK
- 1,509
- 4
- 23
- 49
0
votes
1 answer
Running into error while trying to solve an matrix eigen value problem using numpy that I previously did not run into
This is the error I am getting:
" phi = arctan2(-2zetawn, wn2-w2)
TypeError: ufunc 'arctan2' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' "
In addition…
0
votes
0 answers
np.slerp_vectorized has a different result with other slerp function
I running a project and cant import numpy-quaternion on it. So i have to customize some function. One of them is np.slerp_vectorized. But when i search the formula and try to implement, it has a different result and i dont know if i was wrong or…
0
votes
1 answer
Vectorize Scipy cubic interpolation for multiple Numpy arrays
I have a np.array of 50 elements. For example:
data = np.array([9.22, 9. , 9.01, ..., 7.98, 6.77, 7.3 ])
For each element of the data np.array, I have a x and y data pair (both with the same length) that I want to interpolate with. For example:
x =…

Nelson Salazar
- 21
- 6