Numpy universal functions are "vectorized" functions operating on elements (element by element) on a Numpy array.
Questions tagged [numpy-ufunc]
198 questions
2
votes
1 answer
Faster loop operating on two values of an array
Consider the following function:
def dostuff(n, f):
array = numpy.arange(0, n)
for i in range(1, n): # Line 1
array[i] = f(array[i-1], array[i]) # Line 2
return numpy.sum(array)
How can…

Vincent
- 57,703
- 61
- 205
- 388
1
vote
3 answers
Groupby and transform in pandas based on window conditions
Please help to find an optimal solution for this task.
We have a pandas dataframe with two main date columns and many others (and >20mln rows).
Here is a toy example of the dataset:
df = pd.DataFrame({'date1': [pd.Timestamp('2021-04-15'),…

Ani
- 13
- 5
1
vote
1 answer
I cannot run python runtests.py -v for testing numpy it giving me version issue
I want to run test for numpy library in my local machine but when I simple testing command
like this command
python runtests.py -v
I am keep getting following error
`
Building, see build.log...
Traceback (most recent call last):
File…

Ishaque3 Nizamani
- 51
- 3
1
vote
0 answers
Is there a way either numpy where or numpy selection to sort an array by matching adjacent values
I have an array that represents a series of points. For the purpose of this question the first two columns of the array do not pertain to the problem. The array in question is:
array([[1., 1., 4., 0., 0.],
[1., 1., 8., 0., 0.],
[1.,…

Sushi08
- 11
- 2
1
vote
1 answer
How Can I Convert a String to a Ufunc?
I am trying to write a simple function that converts an input written in LaTeX to a ufunc that can be read by numpy. So far, I'm testing the function by converting \sin(x) to np.sin(x) (ignoring the conversion from {} to (). I'm not that familiar…

Unmaxed
- 15
- 3
1
vote
1 answer
ufunc 'divide' not supported for the input types...... error problem while trying to get the NumPy average
I am new to Numpy and I have been trying to get the average of an array I derived from another array.
This is the code that have been giving me error: "ufunc 'divide' not supported for the input types, and the inputs could not be safely coerced to…

Ayodeji Nicholas
- 11
- 1
- 3
1
vote
1 answer
Strange Error when adding 2 numpy masked arrays
So i'm trying to add 2 numpy masked arrays together. The difficulty is that they have to be added as strings because im trying to get a binary code in the resulting output array. The code below is a simplified version of what i'm trying to do. The…

JacksonFreeman
- 23
- 5
1
vote
1 answer
Numpy duck array with string dtype unexpectedly throws `numpy.core._exceptions._UFuncNoLoopError`
Here is a minimal working example of a simple numpy duck array that I've been using for numeric data.
import numpy as np
class DuckArray(np.lib.mixins.NDArrayOperatorsMixin):
def __init__(self, array: np.ndarray):
self.array = array
…

Roy Smart
- 664
- 4
- 12
1
vote
2 answers
How to compare two vectors using a combination of OR logic and sum
I am trying to apply a method that takes in two vectors and returns a resulting vector.
Below is an example input and expected result:
a = [ 1, 0, -1, 0, 0, 1]
b = [ 0, 0, -1, 0, 1, -1]
result = my_func(a, b)
# [ 1, 0, -1, 0, 1, 0]
My…

achtunette
- 11
- 4
1
vote
2 answers
TypeError: bad operand type for unary -: 'list' python
I Keep getting this error, It's so simple and error is about (-x) in function but I don't know how I can fix it.
Please help me.
This is my code:
import numpy as np
x = list(np.arange(0, 1, 0.1))
print (x)
def f(x):
f = np.exp(-x)
return…

Motahare
- 97
- 2
- 4
1
vote
1 answer
lifetimes library - ISSUE of calculating CLV when using function: customer_lifetime_value of GammaGammaFitter
I'm trying to calculate CLV(Customer Life Value) using lifetimes python library
so, I am fitting purchase behavior data on ParetoNBDFitter and fitting purchase price data on GammaGammaFitter.
and When I'm trying to calculate CLV based on…

오진석
- 21
- 2
1
vote
0 answers
Writing my own ufunc; ufunc not supported for the input types
I'm trying to write a C function that coverts numpy string array to a float array. How can I receive numpy's array in C as const char *?
static void double_logitprod(char **args, npy_intp *dimensions,
npy_intp* steps,…

Saurav Bhattarai
- 40
- 3
1
vote
2 answers
Numpy apply along axis based on row index
Trying to apply numpy inbuilt function apply_along_axis based on row index position
import numpy as np
sa = np.array(np.arange(4))
sa_changed = (np.repeat(sa.reshape(1,len(sa)),repeats=2,axis=0))
print (sa_changed)
OP:
[[0 1 2 3]
[0 1 2 3]]
The…

data_person
- 4,194
- 7
- 40
- 75
1
vote
2 answers
numpy.add.at slower than in-place add?
Proceeding from one of my earlier posts, I noticed that the operation np.add.at(A, indices, B) is a lot slower than A[indices] += B.
def fast(A):
n = A.shape[0]
retval = np.zeros(2*n-1)
for i in range(n):
retval[slice(i,i+n)] +=…

Kevin
- 3,096
- 2
- 8
- 37
1
vote
1 answer
Does Numba support in-built python function e.g. `setitem`
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function() found for signature:
This error is encountered when tried to set all the elements less than a given…

Helal Uddin Mullah
- 23
- 5