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

How to apply textwrap.wrap as ufunc on xarray.Dataarray

I am desperately trying to split strings within an xarray.Dataarray. What should happen to every element of the array is e.g. "aaabbbccc" --> [aaa, bbb, ccc] Fortunately, such a function already exists in the textwrap library, but applying it to my…
0
votes
1 answer

Numpy vectorization and signature

I have the following function: def fun1(a): b=a[0]+a[1] return(b) I want to vectorize it using: fun2 = np.vectorize(fun1,signature='(n,m)->(n,1)') the input input=np.array([ [1 ,2], [3, 4], [5, 6]]) I need the output…
0
votes
0 answers

More precise way to convert numpy array to list?

UPDATE: I went around the problem with a DataFrame: import pandas as pd import numpy as np dict = {'x0':[1,1,1,1,1],'x1':[2,3,5,7,8],'x2':[1,5,3,6,7], 'y':[3,2,4,5,8]} df = pd.DataFrame(dict) # y = β(0) + β1x1 + β2x2 X =…
Pedro
  • 1
  • 1
0
votes
0 answers

ufunc 'subtract' not supported for the input types....inputs could not be safely coerced to any supported types according to the casting rule ''safe''

import numpy as np import xpress as xp p = xp.problem ("Problem") x = np.empty(6+1).tolist() constraint = np.array([140,100,110,100,120,100], dtype = xp.npvar) for i in range(6): x[i] = x[i] <= constraint p.addConstraint(x[i]) y =…
0
votes
0 answers

Access and work with dimension label within xr.apply_ufunc

I was wondering whether there is a way to access and work with dimension labels when using the apply_ufunc function of xarray and @guvectorize of numba. From my understanding, having labeled dimensions is one of the advantages of xarray but I wasn't…
jstew
  • 53
  • 4
0
votes
0 answers

combining non-uniform size 2D arrays into a 3D array in python?

I've searched on stackoverflow but could not find an answer to this specific question. Sorry if it is a naive question, I am a newbie to python. I have three 2d arrays of shapes Shape of arr_X = (1,8), Shape of arr_Y = (1,8), & Shape of arr_Z =…
0
votes
0 answers

AttributeError: 'numpy.int64' object has no attribute 'isnull'

I am trying to do EDA and running below code data = data[~data.age.isnull()].copy() Getting error as "AttributeError: 'numpy.int64' object has no attribute 'isnull'" Please help me if anybody knows. Thanks I tried to convert the values but still did…
0
votes
1 answer

Obtaining multiple plots of a given data

I have this data: s_result = [{'time': array([ 0. , 0.1, 0.2, ..., 299.7, 299.8, 299.9]), 'I': array([10., 10., 10., ..., 0., 0., 0.]), 'S': array([60., 60., 60., ..., 0., 0., 0.]), 'M': array([40., 40., 40., ..., 0., 0., 0.]), 'R':…
teddiclax
  • 35
  • 4
0
votes
0 answers

Why do Python dunder methods override NumPy universal-function-overrides in custom array element?

I am trying to make a Python object (called a Stroke) that can be used as elements in NumPy arrays and operated on by NumPy universal functions. I wish to do the following comparison operation: x = Stroke(...) y = Stroke(...) z = Stroke(...) arr =…
0
votes
1 answer

AttributeError: 'SingleBlockManager' object has no attribute 'log'

I am using a big data with million rows and 1000 columns. I already referred this post here. Don't mark it as duplicate. If sample data required, you can use the below from numpy import * m = pd.DataFrame(array([[1,0], [2,3]])) I have…
The Great
  • 7,215
  • 7
  • 40
  • 128
0
votes
2 answers

How can I make my class more robust to operator/function overloading?

I am writing a class for which objects are initialised with two parameters (a, b). The intention is to assign instances of this class to variables so that I can have an equation written symbolically in Python code, but have operator overloading…
Yaseen
  • 23
  • 5
0
votes
2 answers

numpy.vectorize function signature

I have 2 arrays: >>> a.shape (9, 3, 11) >>> b.shape (9,) I would like to compute the equivalent of c[i, j] = f(a[i, j, :], b[i]) where f(a0, b0) is a function that takes 2 parameters, with len(a0) == 11 and len(b0) == 9. Here, i is iterating on…
user16715836
0
votes
1 answer

np.argsort() implementation is not found

I would like to see how numpy.argsort() works. In the documentation, the source for numpy.argsort() is numpy.core.fromnumeric.py. This is…
Azriel 1rf
  • 147
  • 11
0
votes
0 answers

How to read csv files to numpy arrays including column names in the 0th index

I need to get data from csv files and convert it into a numpy array with the first row being the column titles of the csv files. I have been trying different ways, the headers need to have a unicode character length of
Andrew
  • 105
  • 2
  • 10
0
votes
1 answer

How to get Python ufuncs to return floats larger than the normal float size limit?

I have a NumPy array that includes a number that is a little over 260, and I am running the gamma ufunc from scipy.special on it and it currently returns inf for this entry of the array because the result is over 1e514 and the largest float Python…
Josh Pinto
  • 1,453
  • 4
  • 20
  • 37