Numpy universal functions are "vectorized" functions operating on elements (element by element) on a Numpy array.
Questions tagged [numpy-ufunc]
198 questions
0
votes
1 answer
Numpy how to vectorize python function use np.cumprod
I have a python function:
pval = np.array([1,1,1,1,1,0.999709, 0.99973,0.999743,0.999706, 0.999675, 0.99965, 0.999629])
age1=4
age2=8
def getnpxtocert(mt, age, age2):
val = mt[age]
for i in range(age + 1,age2):
val = val * mt[i]
…

William
- 3,724
- 9
- 43
- 76
0
votes
1 answer
ufunc 'add' did not contain a loop with signature matching types (dtype(' dtype('
I am trying to run this script but it's showing generated error:
UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype(' dtype('

Arijit Goswami
- 1
- 1
0
votes
1 answer
ValueError in numba vectorize for accumulate
I'm trying to write a ufunc with Numba. I read this and incorporated into into my code. So, my basic code which runs is
import numpy as np
arr = np.arange(15).reshape((3,5))
def myadd(x, y):
return x+y
myadd = np.frompyfunc(myadd, 2,…

NNN
- 697
- 1
- 5
- 15
0
votes
0 answers
How to pass "readonly" lookup tables to numpy to avoid the GIL
I'm computing a "similarity function", which mostly resembles the cosine similarity measure, although I apply a couple of tricks to deal with ordinal values and missing values.
These tricks basically consist on getting some pre-computed values from…

castarco
- 1,368
- 2
- 17
- 33
0
votes
0 answers
Replacing error with default value while coercing in numpy array
I'm trying to coerce the values in my NumPy array to float. However, in my array, there might be some values which might not coerce successfully and I want to replace those values with a default value. I do want the speed of NumPy though. I do not…

Saurav Bhattarai
- 40
- 3
0
votes
1 answer
ufunc (min, max, mean, etc) on structured (record) arrays with different dtype
I am working in Python(3.8) with numpy(1.20.3) and trying to perform simple functions on a structured array having different data types.
def test_large_record():
x = numpy.array([0.0, 0.2, 0.3], dtype=numpy.float)
x_2 = numpy.array([0.01,…

Dan
- 13
- 1
- 5
0
votes
1 answer
Extending numpy argmin argmax
I am extending my own data types from numpy and almost everything works. I have both __array_ufunc__ and __array_finalize__ that converts all the universal functions to my own type. However for argmin and argmax the __array_ufunc__,…

user13630254
- 33
- 4
0
votes
1 answer
I keep getting "TypeError: only integer scalar arrays can be converted to a scalar index" while using custom-defined metric in KNeighborsClassifier
I am using a custom-defined metric in SKlearn's KNeighborsClassifier. Here's my code:
def chi_squared(x,y):
return np.divide(np.square(np.subtract(x,y)), np.sum(x,y))
Above function implementation of chi squared distance function. I have used NumPy…

Mushahid Hussain
- 131
- 1
- 4
0
votes
1 answer
Best way to address outer mesh surfaces of a cylinder by FiPy ,
Could I address outer mesh face centers by any FiPy or ... modules?
For a cylinder by radius of 'R', related meshes are created O'grid sweep-like on it. As it seems, 'R' is greater than the most outer mesh face centers; so there is a difference…

Ali_Sh
- 2,667
- 3
- 43
- 66
0
votes
1 answer
Function object with numpy fields doesn't compute value when upon function call
I am absolutly new in Python, and I have difficulties using numpy in following way.
My goal is to make a function object which computes f(input) - g(input)
I have the following class:
class MyFunc:
def __init__(self, f: callable, g: callable):
…

Mark Oulitin
- 31
- 4
0
votes
0 answers
Using an if else statement with numpy for Arithmetic calculations
I want to do a numpy.where() statement where if the length of the PC_list is equal to the length of the numbers then I want the standard deviation to be calculated of the PC_list[0:number].std() and also I want to delete the first number in PC_list:…

tony selcuk
- 709
- 3
- 11
0
votes
0 answers
define a numpy signature for output array of unknown length (for use in numba.guvectorize)
Is it possible to create a signature for a numpy ufunc that returns an 1d array of unknown length?
I have a function that takes in one array x of length (n) and an array of labels y of length (m), performs a reduction and returns the array out of…

Val
- 6,585
- 5
- 22
- 52
0
votes
1 answer
Is there a way to use numpy.outer on only a subset of dimensions?
I have an array of arrays, like this:
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
I would like to calculate the pairwise differences between the array elements, something like:
[[[ 0, 0, 0], [-3, -3, -3]],
[[ 3, 3, 3], [ 0, 0, …

David DAemon Allen
- 53
- 4
0
votes
1 answer
xarray: dealing with multiple return values of different dimensions from ufunc
I have a function that works on a one dimensional array (timeseries) and returns a modified version of the array, plus a coefficient.
I'm using xarray.apply_ufunc to apply this function in parallel to my 3D dask array.
The desired output is a xarray…

Val
- 6,585
- 5
- 22
- 52
0
votes
0 answers
Problem xarray.apply_ufunc on a groupby objects (missing output_dtypes)
I am trying to use xarray.apply_ufunc on the groupby object with dask parallelization but getting error.
Dataset contains daily temperatural data of 30 years over certain location with 1km² grid. So the data shape is 10950x1450x900 (days, Y axis and…

wol
- 142
- 1
- 14