Category "numpy"

Loop Vectorisation

I need to vectorise the following loop using Numpy for performance purposes: for example in client_local_dataset: X.append(example['image'].numpy()) Y

How to replace a list inside a multildimensional array?

I was solving this question on SO and faced a few problems with the methods I was trying. OP has a list which looks like this, a = [[[100, 90, 80, 255],

I am attempting to integrate a sine wave. I am getting a valueError: invalid callable given

import numpy as np import scipy.integrate as integrate time = np.arange(0.0, 1, 0.0001) test = np.sin(time) test2 = integrate.quad(test,0,0.01) I set up ti

Convert 2D meshgrid into a 3D array in Python

I have coordinates (lat, lon) in a meshgrid, and data asociated with each "point". I want to export into a .csv and have each point asociated with the data i wa

how to parse numpy array by line

Use cv2 to process PNG image, I want some areas to be transparent. change point [0, 0, 0, 255] to [0, 0, 0, 0]. for example, # a is ndarray(880, 1330, 4) a = [[

Fit unequal data into Linear Regression Model

How do I fit two unproportional arrays to a regression model? Is it possible to resize/reshape one without loosing the data? I used the code from here but my tr

Splitting Array of Lists into named subarrays

Splitting Arrays for Test Train Essentially I am attempting to convert a pandas dataframe into numpy arrays so that I can run it through a Test/Train. My goal h

Numpy sum of 2D array along axis=1, floating range

I would like to perform a sum of a 2D array over the second axis, but on a range which is variable. Not vectorised it is:` import numpy as np nx = 3 ny = 5 a =

Python find indices of subarrays which are continuous and increasing with difference of 1

The input is always strictly increasing. I could write this with a for loop and lots of if-else conditions, but is there some simple way? Here is an example: in

Attempting to use np.insert in a created class which has subscripts yields "object does not support item assignment" debug

I have defined my own class which takes in any matrix and is defined in such a way to convert this matrix into three numpy arrays inside a parenthesis (which I

Formating a frequency dataframe to a table and a histogram

If I have a frequency table like below: ret < -1(%) -1 < ret < -0.5(%) -0.5 < ret < 0(%) 0 < ret < 0.5(%) 0.5 < ret <

Using cblas_dgemm in C and returning the product matrix in python

I am fairly new to parallel computing and we have been assigned to implement a matrix algorithm in C for later use in python. The problem comes when my function

Images Have Grey Values of True and False

I'm planning to process some images using PyCharm. However, I find a bug and start to find the reason. Finally, I find that the images have grey values of True

Adding new column with first non Nan for each row closest to a chosen column from a dataset Python

Hello I want to create a new column from a given dataset (that I call here "df") with the first non-Nan for each row and closest from a given column For example

Create TensorFlow tensor from two smaller tensors using boolean mask

I'm using TensorFlow and would like to create a 1D tensor t1 from two smaller tensors t2 and t3, where len(t2) + len(t3) == len(t1) and a boolean mask which ind

How to combine two columns in pandas dataframe and set values to them?

I have two columns in pandas dataframe Latitude and Longitude. I am trying two combine them in single column LOCATION. If we see the data there are only two loc

How to read a C struct (or Numpy record array) into a Polars Dataframe?

I have a binary file containing records from a C struct. I would like to read that file into a Polars Dataframe. I can accomplish that as below, but I'm wonderi

Problem by using for loop when loading data series from .csv file and save them as array matrix for every columns loaded

I want to load a series of data from 6 CSV files and save them per column of the data series. As I call the Column_A, Column_B and new_Column_A, only the last o

Python: extracting specific values out an numpy array of indices

I have a numpy array of indices. For example: indices = np.array([0, 1, 2, 6, 7, 9, 12, 13, 14]) I would like to make an array signals = np.zeros(np.amax(indi

How to solve Numpy installing error in windows 10, (Python 64 bit)?

I was installing numpy in python latest version 3.10.4 (64bit) after installation of python I did this below in cmd window. C:\Users\Administrator>mkdir pyve