Category "numpy"

When one of my column in dataframe is nested list, how should i transform it to multi-dimensional np.array?

I have the following data frame. test = { "a": [[[1,2],[3,4]],[[1,2],[3,4]]], "b": [[[1,2],[3,6]],[[1,2],[3,4]]] } df = pd.DataFrame(test) df a b 0

How do I select values from one array based on a boolean array?

Let's say I have 2 numpy arrays, with the same 1200x1200 shape. The first one contains boolean values. The second one is an image, that was converted to boolean

Quantify longest axis and width of irregular shapes within a single image

Original question I have about 80-100 images such as (A). Each image is composed of shapes that were filled with black color after marking the outline in ImageJ

can't convert cuda:0 device type tensor to numpy

As metioned in the title, I am getting this TyperError for the following code I am using google collab and is set to GPU runtime type. %%time history = [evaluat

AttributeError: 'numpy.ndarray' object has no attribute 'columns' even after using pandas dataframe

import pandas as pd import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split,cross_val_score from sklearn.tree import DecisionTreeCl

Pandas: Calculate Difference between a row and all other rows and create column with the name

We have data as below Name value1 Value2 finallist 0 cosmos 10 20 [10,20] 1 network 30 40 [30,40] 2 unab 20 40 [20,40]

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