Category "numpy"

Define a function with a fractional power in python

I want to defining the following function: def f(x,y): return pow(x, 1/3) + y x = np.linspace(-1, 1, 10) y = np.linspace(-1, 1, 10) X, Y = np.meshgrid(x,

Numpy indices in quadrilateral

Is there a smart way to get the indices of all the entries within four points? In particular this is about the case where I have four points (x_1, y_1), (x_1, y

numpy where with multiple conditions linked to dataframe

I'm using numpy where with multiple conditions to assign a category based on a text string a transaction description. Part of the code is below `import numpy as

Kronecker product of 3 matrices using Python

Suppose that we have 2 2X2 numpy arrays: X=np.array([[0,1],[1,0]]) and I=np.array([[1,0],[0,1]]) Consider the Kronecker product XX=X^X where I have let the s

How to subtract 1 dimension Numpy arrays with different shapes and plot the difference in seaborn or matplotlib? [duplicate]

Basically I have these arrays print(img_arr[0].shape)->(returns) (122218,) print(img_arr1[0].shape)->(returns) (125204,) so when I did

"incompatible architecture (have 'arm64', need 'x86_64')" error while installing numpy on M1 Mac with pip3 on Python Version 3.10

I was trying to install numpy version 1.22.3 on a M1 Macbook with pip3, and pip3 says the package is present, but when I try to import the module, an error gets

AttributeError: 'int' object has no attribute 'split' pandas

Please, I know there are several issues related to this error of mine, but I'm learning, I don't understand almost anything, so please, if it's not asking too m

How to plot a streamplot in python for a streamline flow arround a cylinder?

I have written a program where it takes a radius range(R to 5) and theta range(0 to 2pi). It converts the polar coordinates to Cartesian coordinates. Then I hav

How do I check which rows of one small array exists in another larger one?

How do I check which rows of one small array exists in another larger one? Given the following setup: final_batch = np.emtpy((batch_size,2)) batch_size = 4 a =

selecting an xarray dataset by coordinates instead of dimensions (or switching coordinates to dimensions)

I have a, xarray dataset that is ocean color of the Atlantic Ocean called olci_ds. This dataset has dimensions of rows and columns and coordinates of lat, lon a

No BLAS/LAPACK libraries found when installing SciPy on macOS

I am using python 3.9.8 and pycharm on a macbook m1. I have already installed openblas with homebrew but I still get the error below. I tried installing SciPy v

How to calculate average pixel intensity inside a laser line in Python?

I am trying to write a code that calculates the speckle contrast of a laser line. Here is an example of an image that I would be analyzing: The image is black w

Python 3 RuntimeWarning: overflow encountered in double-scalars - trying to fit multiple gaussians and an offset using scipy.optimise.curve_fit

Hi all as with many peeps, I am new to python. Updated script that runs to completion but has a OptimizeWarning: Covariance of the parameters could not be estim

How to optimise reading multiple files containing bytes into a NumPy array

I currently have ~1000 files containing bytes. Each file contains a few thousand messages, each message has identical data types. I've tried several ways of rea

Is there unstack in NumPy?

There is np.stack in NumPy, but is there an opposite np.unstack same as tf.unstack?

How can I use scipy interp1d with N-D array for x without for loop

How can I use scipy.interpolate.interp1d when my x array is an N-D array, instead of a 1-D array, without using a loop? The function f from interp1d then needs

Render NumPy array in FastAPI

I have found return numpy array as image from fastapi but I am still struggling to show my image which just appears as a white square. I read an array into io.B

Getting error while generating heatmap in python:ValueError: Must pass 2-d input. shape=()

I am getting errors while generating maps of h3 moments in python for an image file called "image_test". The error apparently is for the shape of the values tha

Signal correlation shift and lag correct only if arrays subtracted by mean

If I have two arrays that are identical except for a shift: import numpy as np from scipy import signal x = [4,4,4,4,6,8,10,8,6,4,4,4,4,4,4,4,4,4,4,4,4,4,4] y =

How to create a new columns based off of values of other columns which could contain #s or NaN?

I have a few dataframes that I'm merging based on known, populated fields. The resulting dataframe will always contain a set of columns, but may or may not have