Numpy universal functions are "vectorized" functions operating on elements (element by element) on a Numpy array.
Questions tagged [numpy-ufunc]
198 questions
1
vote
0 answers
How do I optimize a 1D interpolation on a multidimensional dataarray?
I have a 4D dataarray and I'm interpolating it only along the vertical axis.
from scipy.interpolate import interp1d
#data array dims
da[time,plev,la,lon]
#array with vertical levels
lev = da.plev
#new temperatures ->dummy values
tem =…

SxS
- 41
- 3
1
vote
0 answers
Overloading math operations of numpy.ndarray subclass
I have a class that is a subclass of numpy.ndarray. Following this example I have a class Test that behaves like numpy.ndarray but has an additional attribute description:
>>> f = Test([0., 1., 2.], description="f")
>>> f
array([0., 1., 2.])
>>>…

Sebastian
- 755
- 3
- 7
- 22
1
vote
0 answers
Construct symmetric block matrix in Python
For example, I got the following 2D array
a= np.array([[1,2,3],
[2,5,6],
[3,6,9]])
If I know the dimension of each block square matrix of diagonal, i.e
2,3,2
How can I generate the following 2D block…

Nicolas H
- 535
- 3
- 13
1
vote
0 answers
Fitting a polynomial to chunks of a large CMIP6 NetCDF xarray?
My goal is to calculate a quadratic fit over the time-dimension of 'zos' (sea level) data of piControl runs of various CMIP6 models and subtract that from other runs. In this particular example, the data looks as follows:
Out[108]:…

Tim Hermans
- 11
- 2
1
vote
1 answer
What is the precise meaning of question marks in an einsum-like gufunc signature?
For example:
np.arange(3)@np.arange(2)
# Traceback (most recent call last):
# File "", line 1, in
# ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 2 is…

Paul Panzer
- 51,835
- 3
- 54
- 99
1
vote
1 answer
How to create a video from numpy array without looping?
I want to make a video from array which shape is (70000, 640, 480, 3).
the first axis is the number of photos which I want to collect them into a video without using loops to append each photo .

Ahmed Mohamed
- 28
- 4
1
vote
1 answer
Is there a way to use numpy to apply a function to a 2D array without a loop
I'm trying to convert a list of quaternions to their corresponding orientation matrix using the Transforms3d python package.
Each quaternion is a 4 element list/array of the inputs and using the transforms3d.quaternions.quat2mat(q) function it…

jpmorr
- 500
- 5
- 25
1
vote
2 answers
How to overide numpy ufunc with __array_ufunc__
I'm trying to implement numpy's ufunc to work with a class, using the __array_ufunc__ method introduced in numpy v1.13.
To simplify, here's what the class could look like :
class toto():
def __init__(self, value, name):
self.value =…

mocquin
- 402
- 3
- 11
1
vote
1 answer
Numpy vectorize signature definition - ValueError
I am trying to use Python/Numpy vectorized functions to reduce for loops.
My function call looks like this
out_vectors = v_calculation(
in_vectors,
p
)
The vectorized function definition…

gordon macmillan
- 123
- 3
- 13
1
vote
2 answers
How to make Hadamard product along axis with numpy?
I am trying to make the Hadamard product of a 3-D with a 2-D array. The 2-D array shares the shape of the first two axes of the 3-D array and should be moved along the 2 axis (thus, the 3rd) for the multiplications, meaning: make Hadamard product…

lcnittl
- 233
- 1
- 14
1
vote
1 answer
ufunc memory consumption in arithemtic expressions
What is the memory consumption for arithmetic numpy expressions I.e.
vec ** 3 + vec ** 2 + vec
(vec being a numpy.ndarray). Is an array stored for each intermediate operation? Could such compound expressions have multiple times the memory than…

michaelkovarik
- 113
- 2
1
vote
0 answers
Pandas: Applying custom aggregation function (not w/ groupby)
We can think of applying two types of functions to a Pandas Series: transformations and aggregations. They make this distinction in the documentation; transformations map individual values in the Series while aggregations somehow summarize the…

Dylan B
- 173
- 1
- 1
- 13
1
vote
2 answers
python-xarray: Compute the absolute values of a dataset
np.fabs works fine on xr.DataArray's but not xr.Dataset's.
data = xr.DataArray(np.random.randn(2, 3), coords={'x': ['a', 'b']}, dims=('x', 'y'))
ds = xr.Dataset({'foo': data, 'bar': ('x', [1, 2]), 'baz': np.pi})
np.fabs(ds)
TypeError: ufunc 'fabs'…

Ray Bell
- 1,508
- 4
- 18
- 45
1
vote
1 answer
What is the default of numpy functions, with where=False?
The ufunc documentation states:
where
New in version 1.7.
Accepts a boolean array which is broadcast together with the operands. Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the…

Jürg W. Spaak
- 2,057
- 1
- 15
- 34
1
vote
1 answer
Multiplication and dot product with adjacency matrices (numpy)
I am using the following chunk of code with networkx, when I discovered the following oddity. In the first case, I used the ufunc multiply(*) on a sparse matrix that unexpectedly correctly giving me a degree sequence. However, when the same is done…

buzaku
- 361
- 1
- 10