Numpy universal functions are "vectorized" functions operating on elements (element by element) on a Numpy array.
Questions tagged [numpy-ufunc]
198 questions
0
votes
0 answers
what does ufunc 'subtract' did not contain a loop with signature matching types means
I'm trying to write a gaussian pulse function which you can see in the picture (named g(t)) or below. Gaussian pulse
g(t) = rect(t/T)exp((-(t-t0)^2)/(sigma)^2)exp(i2pif_ct)
Where -t is the time and my variable for my x axis
-t0,sigma and f_c are…

Marie
- 1
- 1
0
votes
0 answers
Numpy function gives unexpected output while using np.where()
A small intro to my question.
I want to plot a sound file with numpy in dB. Just doing 20 * np.log10(arr) doesn't work because of negative numbers.
So I was looking into using np.where(). because np.where() is part of ufunc I just want to do it in…

Jan-Bert
- 921
- 4
- 13
- 22
0
votes
3 answers
Can a "ufuncify" function be set up to take complex input? "ufunc 'wrapper_module_0' not supported for the input types" error
I am just learning how to use sympy for symbolic variable manipulations. I now have an expression that I'd like to evaluate many times in an optimization scheme, so I'd like for it to run very quickly. The sympy documentation on Numeric Computation…

Drphoton
- 164
- 9
0
votes
1 answer
Numpy multidimensional indexing for np.ufunc.at and np.ix_
I would like to know how I can take index from an array and multiply with another array. I have two 4d arrays and one 2d index array:
base = np.ones((2, 3, 5, 5))
to_multiply = np.arange(120).reshape(2, 3, 4, 5)
index = np.array([[0, 2, 4, 2], [0,…

MachineLearner
- 413
- 5
- 10
0
votes
1 answer
using numpy fromfunction to fill a matrix with a custom function
This is related to another question I have except there I am looking for a vectorized/broadcasting solution.
Here I am hoping to try using np.fromfunction but am having issues.
The MWE is
# L1 and L2 will range from 0 to 3 typically, sometimes up to…

Dilbert
- 101
- 2
0
votes
0 answers
Apply function to Xarray dataset
I am trying to apply a function to an Xarray dataset, using dataset.where mask to decide where to apply it. I am not sure how to do it.
Some context: the dataset has two variables (A and B), which are two overlapping raster images (same size and…

ffgg
- 134
- 1
- 8
0
votes
1 answer
Assigning an array value into a multidimensional numpy array based on an equality comparison condition?
I am new to numpy multidimentional arrays, and getting stuck on what seems like it should be an "easy" concept.
In the code below, fakepng represents an RGBA image inside of a numpy array. I want to set the alpha channel to 0 for of every pure black…

Kevin Hakanson
- 41,386
- 23
- 126
- 155
0
votes
0 answers
How to implement ufunc 'matmul' using Numpy-C API?
I am trying to implement a custom datatype with built-in support for numpy using Numpy-C API.
My code is based on the quaterion implementation by https://github.com/moble/quaternion.
Currently that project has supported functions like 'add',…

Shen Messy
- 11
- 1
0
votes
1 answer
Automatically masking a numpy array for a given operation
Say I have two numpy arrays, for example
import numpy as np
A = np.arange(5*3*3*2).reshape(5, 3, 3, 2)
B = np.arange(3*3).reshape(3, 3)
If I want to add A and B across a shared axis, I would just do
C = A + B[None, :, :, None]
# C has shape (5, 3,…

user3166083
- 147
- 8
0
votes
1 answer
Matplotlib Barbs as a function of time vs. height - unknown error
I have data that has wind speed/direction for 16 different height levels. This data is recorded in 1 minute intervals. I am attempting to create a 2-d chart that has the height levels on the y-axis and time on the x-axis.
00:00, ws_10feet,…

Jonathon
- 251
- 1
- 7
- 20
0
votes
0 answers
Applying numpy array of functions to a single input
I'm trying to achieve something of this sort:
f1 = lambda x: x**2
f2 = lambda x: x**3
fn = np.array([f1, f2])
print(fn(3))
So that it returns an array with the outputs in place. Of course, I could do it like this:
result = np.array([f(x) for f in…

amzon-ex
- 1,645
- 1
- 6
- 28
0
votes
1 answer
Please explain unravel_index when order='F'
I understood unravel_index in general but don't get how this example works :
np.unravel_index([31, 41, 13], (7,6), order='F')

ravi s
- 1
- 1
0
votes
1 answer
np.ufunc.at for 2D array
In order to compute confusion matrix (not the accuracy) loop over the predicted and true labels may be needed. How to perform that in a numpy manner, if next code does not give needed result?
>> a = np.zeros((5, 5))
>> indices = np.array([
[0,…

A.Ametov
- 1,790
- 1
- 13
- 20
0
votes
1 answer
Truth value of a series is ambiguous - Creating new dataframe column based on another columns values
I'm trying to create a new column designating the region of a state based on the state alpha code column. I've reviewed other questions, and tried both using .apply and using np.select as shown below. Can someone please help me fix the code, and…

Shawn Schreier
- 780
- 2
- 10
- 20
0
votes
0 answers
Pandas approach to apply functions across multiple columns with same index?
I have a basic Pandas DataFrame, something like:
In [2]: print(pd
.DataFrame({
'a': pd.Index([1,2,3, 1,2,3]),
'b': pd.Categorical(['can','foo','bar', 'can','foo','bar']),
…

A T
- 13,008
- 21
- 97
- 158