Category "numpy"

Python Numpy: replace values in one array with corresponding values in another array

I am using Python Numpy arrays (rasters converted to 2D arrays, specifically) and what I want to do is take one array that has arbitrary dummy values of -999 re

Adding row/column headers to NumPy arrays

I have a NumPy ndarray to which I would like to add row/column headers. The data is actually 7x12x12, but I can represent it like this: A=[[[0, 1, 2, 3, 4, 5]

How to display a text with matplotlib

I would like to do this : I have this python code : import numpy as np import pylab as plt a = np.array([1,2,3,4,5,6,7,8,9,10]) b = np.array([7,8,6,3,2,1,5,8,4

Linear index upper triangular matrix

If I have the upper triangular portion of a matrix, offset above the diagonal, stored as a linear array, how can the (i,j) indices of a matrix element be extrac

numpy's interp function - how to find a value of x for a given value of y?

So I have an array of values of x (in increasing order) and the corresponding y values. Numpy's interp function takes in the X value, and the x and y arrays. Ho

Logical indexing - numpy.where in C++

I have created a simple numpy array with shape (4, 2) called A. import numpy as np A = np.array([[1, 2], [2, 2], [3, 2],

PyArray_Check / PyArray_CheckExact gives segmentation fault

In c++, I define the following module: #include <boost/python.hpp> #include <numpy/arrayobject.h> bool foo(PyObject *obj) { if (!PyArray_Check

AttributeError: 'MachAr' object has no attribute 'smallest_subnormal'

When importing librosa library, this error has occurred. C:\Users\jssong\anaconda3\envs\tensor_v2\lib\site-packages\numpy\core\getlimits.py:492: UserWarning: Si

Python poetry install failure - invalid hashes

I'm unsure exactly what information / context to provide with this post in order for it to be properly answered - so if I can add more information please let me

Numpy argmax - random tie breaking

In numpy.argmax function, tie breaking between multiple max elements is so that the first element is returned. Is there a functionality for randomizing tie brea

Upsample and Interpolate a NumPy Array

I have an array, something like: array = np.arange(0,4,1).reshape(2,2) > [[0 1 2 3]] I want to both upsample this array as well as interpolate the re

how to fill a Pandas dataframe column with a list containing string values

I have a dataframe with 142 rows. I have created a new column. I want to fill this new column with a list containing strings. my_list = ['abc','def','hig'] df[

Does Pandas, SciPy, or NumPy provide a cumulative standard deviation function?

I have a Pandas series. I need to get sigma_i, which is the standard deviation of a series up to index i. Is there an existing function which efficiently calcul

Why does PyCharm give unresolved reference errors on some Numpy imports?

The following line in PyCharm is flagged by on-the-fly inspection with unresolved reference errors for each import. (They are underlined red.) from numpy impor

numpy random choice in Tensorflow

Is there an equivalent function to numpy random choice in Tensorflow. In numpy we can get an item randomly from the given list with its weights. np.random.c

How to mask image with binary mask?

Suppose I have a greyscale image here: And a binary masked image here: With the same dimensions and shape. How do I generate something like this: Where the v

Python OpenCV - How to save a 5 channel image

I'm using Google Colab with Python 3 and I need to merge 3 images to make a new one with 5 channels, but i get this error: error: OpenCV(4.1.2) /io/opencv/modu

How can I reshape a Pandas DataFrame to show if certain values in a column are present by day?

I'm writing a script to query a database and return a DataFrame, df, that looks like this: cost data_source process_date revenue 0 0.796895

numpy: formal definition of "array_like" objects?

In numpy, the constructors of many objects accept an "array_like" as first argument. Is there a definition of a such object, either as an abstract meta class, o

How to printing numpy array with 3 decimal places? [duplicate]

How can I print numpy array with 3 decimal places? I tried array.round(3) but it keeps printing like this 6.000e-01. Is there an option to mak