Category "numpy"

How do I generate a sine wave using Python?

I'm trying to generate a sine wave of a given frequency for a given duration and then write it into a .wav file. I'm using numpy's sin function and scipy's wavf

Get for each row the last column name with a certain value

I have this kind of dataframe, and I'm looking to get for each row the last column name equals to 1 Here is an example of my dataframe col1 col2

Numpy array of tuples to PIL image

I currently have a numpy array or RBG tuples that I want to convert to a PIL image and save. Currently I'm doing the following: final = Image.fromarray(im_arr,

Using scipy gaussian kernel density estimation to calculate CDF inverse

The gaussian_kde function in scipy.stats has a function evaluate that can returns the value of the PDF of an input point. I'm trying to use gaussian_kde to esti

numpy arange: how to make "precise" array of floats?

In short, the problem I encounter is this: aa = np.arange(-1., 0.001, 0.01) aa[-1] Out[16]: 8.8817841970012523e-16 In reality, this cause a series problem si

Calculating interest rates in numpy

Hopefully this is a quick and easy question that is not a repeat. I am looking for a built in numpy function (though it could also be a part of another library)

Find the first and last element of a NumPy array larger than a threshold

I need to find the first and the last element of a numpy.ndarray which are above a specified threshold. I found the following solution, which works, but it look

ValueError: Can't convert non-rectangular Python sequence to Tensor

I want to change list to tensor with tf.convert_to_tensor, data is following: data=[ array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.

How to apply a function to a 2D numpy array with multiprocessing

Suppose I have the following function: def f(x,y): return x*y How do I apply the funtion to each element in an NxM 2D numpy array using the multiprocessi

Fastest way to store a numpy array in redis

I'm using redis on an AI project. The idea is to have multiple environment simulators running policies on a lot of cpu cores. The simulators write experience

AssertionError: Wrong values for d['w'] | deeplearning specialization

I was completing the first course of the deeplearning specialization, where the first programming assignment was to build a logistic regression model from scrat

Is there a way to convert numpy array to PNG/JPG... payload without saving it as a file?

Suppose there exists a numpy array, data. I am trying to do the equivalent of the following cv2.imwrite(filename, data) with open(filename, 'rb') as fp: da

pandas astype python bool instead of numpy.bool_

I need to convert a pandas dataframe to a JSON object. However json.dumps(df.to_dict(orient='records')) fails as the boolean columns are not JSON serializa

numpy equivalent code of unsqueeze and expand from torch tensor method

I have these 2 tensors box_a = torch.randn(1,4) box_b = torch.randn(1,4) and i have a code in pytorch box_a[:, 2:].unsqueeze(1).expand(1, 1, 2) but i want to

pandas diff() giving 0 value for first difference, I want the actual value instead

I have df: Hour Energy Wh 1 4 2 6 3 9 4 15 I would like to add a column that shows the per hour differenc

cannot unpack non-iterable numpy.float64 object python3 opencv

I am getting this error and cant understand why the issue is appearing. Below will be the code and error. The result of the last printable workout [-8.545822

How to initialize a buffer object's data store with data from PyGLM?

I use PyGLM and PyOpenGL I have specified the following Shader Storage Buffer in the Vertex Shader: layout(std430, binding = 1) buffer MVP { mat4 u_proj;

How would I check if each cell of an array has neighbors of a specified value quickly in numpy?

Say I have an array like np.array([[0,0,0,1,0], [0,0,0,0,0], [0,1,0,0,0], [0,0,0,1,0], [0,0,0,0,

Looping over pandas DataFrame

I have a weird issue that the result doesn't change for each iteration. The code is the following: import pandas as pd import numpy as np X = np.arange(10,100)

Normalized Cross-Correlation in Python

I have been struggling the last days trying to compute the degrees of freedom of two pair of vectors (x and y) following reference of Chelton (1983) which is: