Questions tagged [numpy-ufunc]

Numpy universal functions are "vectorized" functions operating on elements (element by element) on a Numpy array.

198 questions
0
votes
0 answers

Implementing numpy einstein summation for sum of dot products

I need to optimize an algorithm, which needs to be fast as possible, for now, its a basic sum over the dot products of 2 vectors problem, but I think my solution is a bit redundant, and Einstein notation can get much faster results. First, I had a…
Olca Orakcı
  • 372
  • 3
  • 12
0
votes
0 answers

Errors using numpy.meshgrid with matrix functions in Python

I want to 3D plot a f(x,y) function that uses several matrix operation. I want to look for possible maximum and minimums. The reason of this matrix operation is that sometimes this type of functions can be expressed in a cleaner an more compact…
Ivan
  • 119
  • 1
  • 8
0
votes
1 answer

How to use numpy's random number generator in a ufunc?

Basically I have a ufunc that requires some randomness. In order to keep the ufuncs as reproducible as possible I would like to use numpy's random number generator for that; basically because setting the seed will be more intuitive this way. However…
LittleByBlue
  • 436
  • 9
  • 18
0
votes
1 answer

How to treat complex values when writing a numpy ufunc?

Basically I have a numpy ufunc that operates on npy_cdouble and npy_cfloat arrays. For instance: static void ufunc_H( char ** args , npy_intp * dimensions , npy_intp * steps , void * data) { npy_cdouble * qm_in =…
LittleByBlue
  • 436
  • 9
  • 18
0
votes
1 answer

How to prevent numpy from collapsing rows?

I have a function which takes a numpy array and outputs a numpy array. However, when the output array contains a constant value, calling the function with a numpy array results in said value being "collapsed". I'm trying to write a vector calculus…
0
votes
0 answers

Is it possible to write these 2 functions in Python without using numpy?

I'm trying to plot without using Numpy, but what can I write as an alternative to the following functions? The alternatives I found to some functions gave different outputs. vel = np.zeros([n, m, 2], dtype = float) -----> vel = [ [ [0.0 for i in…
0
votes
0 answers

Custom "inner product" / "outer product"

I have the following code structure: result_matrix = np.zeros((n,n)) for i in range(data1.shape[0]): for j in range(data1.shape[1]): result_matrix[i,j] = myfct(data1[i,:], data2[:,j]) Can we solve this with a more numpy-y way - possibly…
Make42
  • 12,236
  • 24
  • 79
  • 155
0
votes
1 answer

NumPy right_shift gives all zeros

I have a = np.array([300, 320, 616], dtype=np.uint16) b = np.right_shift(a, 8, dtype=np.uint8) which results in all-zero b. Can you please explain this behavior?
hovnatan
  • 1,331
  • 10
  • 23
0
votes
1 answer

AttributeError: 'numpy.ufunc' object has no attribute '__module__'

I have installed skimage using 'pip install scikit-image' inside a conda environment. I am using python 2.7. When I try importing : from skimage import transform It gives me the error: AttributeError: 'numpy.ufunc' object has no attribute…
sarath s
  • 3
  • 1
  • 3
0
votes
1 answer

Evaluate array valued function python 3

I need to integrate a matrix function as in the example below: def func(a1, a2, a3): return np.array([a1, (a1 + a2), a3]) The non-efficient way to do this is using three for loops. Although, I would like to make it more efficient. I thought…
Gabs
  • 292
  • 5
  • 23
0
votes
1 answer

How can I map a vectorized function to a numpy array without using a for loop?

So here's what I already have: import numpy as np import matplotlib.pyplot as plt def monteCarloPi(n): np.random.seed() #seed the random number generator y = np.random.rand(n)*2 - 1 #n random samples on (-1,1) x =…
datBoi
  • 1
  • 1
0
votes
2 answers

How to make a ufunc output a matrix given two array_like operands (instead of trying to broadcast them)?

I would like to get a matrix of values given two ndarray's from a ufunc, for example: degs = numpy.array(range(5)) pnts = numpy.array([0.0, 0.1, 0.2]) values = scipy.special.eval_chebyt(degs, pnts) The above code doesn't work (it gives a ValueError…
gsarret
  • 160
  • 2
  • 7
0
votes
1 answer

Numpy equal dtype

Should the keyword argument dtype is not considered in np.equal? In the function documentation, it seems to indicate that dtype should a valid keyword argument, and I couldn't find anything saying that it will be ignored, but when using logical…
cnapun
  • 93
  • 6
0
votes
1 answer

Simulate numpy vectorized function on a meshgrid

This is the example given on how to use numpy.meshgrid x = np.arange(-5, 5, 0.1) y = np.arange(-5, 5, 0.1) xx, yy = np.meshgrid(x, y, sparse=True) z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2) What if I have a meshgrid like xx,yy above, but my…
Ivan
  • 7,448
  • 14
  • 69
  • 134