Category "numpy"

Debugging Numpy VisibleDeprecationWarning (ndarray from ragged nested sequences)

Since NumPy version 19.0, one must specify dtype=object when creating an array from "ragged" sequences. I'm faced with a large number of array calls from my own

Numpy where function multiple conditions

I have an array of distances called dists. I want to select dists which are within a range. dists[(np.where(dists >= r)) and (np.where(dists <= r + dr))]

How can I convert boolean values from np.diff() to the actual values

I have a numpy array of np.shape=(n,) I am attempting to iterate through each value of the array and subtract the 2nd value from the 1st, then see if the differ

How to copy a 2D array into a 3rd dimension, N times?

I'd like to copy a numpy 2D array into a third dimension. For example, given the 2D numpy array: import numpy as np arr = np.array([[1, 2], [1, 2]]) # arr.shap

How to scale a dataframe with datetime field in it (as a index)?

I want to scale a dataframe, which raises the error as in the title (or below). My data: df.head() timestamp open high low close volume 0 2020-06-2

Pyplot Imshow Autozoom to cut out Irregular NaN padding

I have the following code import matplotlib.pyplot as plt import numpy as np array = np.pad(np.random.rand(300,300),10,'constant', constant_values = nan) fi

Implement Relu derivative in python numpy

I'm trying to implement a function that computes the Relu derivative for each element in a matrix, and then return the result in a matrix. I'm using Python and

How do I convert numpy mgrid function as a function?

Here is the way how numpy.mgrid is used. grid = np.mgrid[x1:y1:100j , x2:y2:100j, ..., xn:yn:100j] However, I find this structure very irritating. Therefore, I

solving Ax =b for a non-square matrix A using python

I'm focusing on the special case where A is a n x d matrix (where k < d) representing an orthogonal basis for a subspace of R^d and b is known to be inside t

Updating a NumPy array with another

Seemingly simple question: I have an array with two columns, the first represents an ID and the second a count. I'd like to update it with another, similar arr

How to change array shapes in in numpy?

If I create an array X = np.random.rand(D, 1) it has shape (3,1): [[ 0.31215124] [ 0.84270715] [ 0.41846041]] If I create my own array A = np.array([0,1,2]

Numpy mask based on if a value is in some other list

I have searched high and low and just can't find a way to do it. (It's possible I was searching for the wrong terms.) I would like to create a mask (eg: [True F

Reading coef value from OLS regression results

I use pandas and statsmodels to do linear regression. However, i can't find any possible way to read the results. the results are displayed but i need to do som

How to fix Python Numpy/Pandas installation?

I would like to install Python Pandas library (0.8.1) on Mac OS X 10.6.8. This library needs Numpy>=1.6. I tried this $ sudo easy_install pandas Searching

How to find all neighbors of a given point in a delaunay triangulation using scipy.spatial.Delaunay?

I have been searching for an answer to this question but cannot find anything useful. I am working with the python scientific computing stack (scipy,numpy,matp

Adding a vector to matrix rows in numpy

Is there a fast way in numpy to add a vector to every row or column of a matrix. Lately, I have been tiling the vector to the size of the matrix, which can use

How to invert a permutation array in numpy

Given a self-indexing (not sure if this is the correct term) numpy array, for example: a = np.array([3, 2, 0, 1]) This represents this permutation (=> is

python read zipfile into numpy-array efficiently

I want to read a zipfile into memory and extract its content into a numpy array (as numpy-datatypes). This needs to happen in an extremely efficient/fast manner

NumPy: get min/max from record array of numeric values

I have a NumPy record array of floats: import numpy as np ar = np.array([(238.03, 238.0, 237.0), (238.02, 238.0, 237.01), (238.05

numpy mean of complex numbers with infinities

numpy seems to not be a good friend of complex infinities While we can evaluate: In[2]: import numpy as np In[3]: np.mean([1, 2, np.inf]) Out[3]: inf The f