Category "numpy"

Python Numpy - Treat really small numbers as zero

I want to calculate the Determinant of a Singular Matrix (which has a 0 determinant) with Numpy and when I print the determinant it shows a really small number

Why is numpy.linalg.pinv() preferred over numpy.linalg.inv() for creating inverse of a matrix in linear regression

If we want to search for the optimal parameters theta for a linear regression model by using the normal equation with: theta = inv(X^T * X) * X^T * y one step

NumPy 2D array: selecting indices in a circle

For some rectangular we can select all indices in a 2D array very efficiently: arr[y:y+height, x:x+width] ...where (x, y) is the upper-left corner of the rec

how to remove duplicated elements from a list without using set()?

Let a = np.array([1, 1, 1,1,1,1]) b = np.array([2,2,2]) be two numpy arrays. Then let c = [a]+[b]+[b] clearly, c has duplicated elements b. Now I wish to

ImportError: No module named numpy on spark workers

Launching pyspark in client mode. bin/pyspark --master yarn-client --num-executors 60 The import numpy on the shell goes fine but it fails in the kmeans. Someho

Take average of every 2 consecutive elements and insert them back into array

I have an array and want to find the average between 2 numbers and add an additional element between the 2 numbers. For example, if I start with x = np.array([1

How to create a Python convolution kernel?

I'm trying to create a convolution kernel, and the middle is going to be 1.5. Unfortunately I keep running in to ideas on how to do that. I'm trying to create s

Use a.any() or a.all()

x = np.arange(0,2,0.5) valeur = 2*x if valeur <= 0.6: print ("this works") else: print ("valeur is too high") here is the error I get: if vale

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