Category "numpy"

Stratified Sampling in Pandas

I've looked at the Sklearn stratified sampling docs as well as the pandas docs and also Stratified samples from Pandas and sklearn stratified sampling based on

Compute maxima and minima of a 4D tensor in PyTorch

Suppose that we have a 4-dimensional tensor, for instance import torch X = torch.rand(2, 3, 4, 4)

How to fix Python error "...failed to map segment from shared object" appearing when I try to import NumPy library on GCP?

I've recently started to use Google Cloud Platform and I run my python scripts in Cloud Shell within Linux environment. By running one of the scripts that is u

Extract misclassified images using CNN keras

I am having difficulties extracting misclassified images, I tried to use the following line of code: inc= np.nonzero(model.predict_classes(test_data).reshape(-

Matplotlib: display element indices in imshow

From this answer I know how to plot an image showing the array values. But how to show the i,j indices of each element of the array, instead of the values thems

Can numpy.tensordot or ufunc replace this nested for loop?

Note: I know this is very similar to Use numpy.tensordot to replace a nested loop , only that the actual instance we are working on seemed different( I need qua

create cosine similarity matrix numpy

Suppose I have a numpy matrix like the following: array([array([ 0.0072427 , 0.00669255, 0.00785213, 0.00845336, 0.01042869]), array([ 0.00710799, 0.00

Find positions of elements in sorted array

Suppose I have some numpy array (all elements are unique) that I want to sort in descending order. I need to find out which positions elements of initial array

Load numpy array in google-cloud-ml job

In the model I want to launch, I have some variables which have to be initialized with specific values. I currently store these variables into numpy arrays but

How to append an array to an existing `.npz` file?

I have the following code, which generate the mat file (in .npz format): import numpy as np x = np.arange(10) np.savez('mat',x) Now I want to append another

Convert numpy array from space separated to comma separated in python

This is data in .csv format file generally we expect array/ list with [1,2,3,4] comma separated values which it seems that nothing happened in this case data =

How do I find the KL Divergence of samples from two 2D distributions?

Suppose I had two 2D sets of 1000 samples that look something like this: I'd like to have a metric for the amount of difference between the distributions and

Using matplotlib to create a spectrogram of a wavfile

import scipy.io.wavfile as wav import matplotlib.pyplot as plt import scipy sample_rate, X = wav.read("/Users/sinaastani/Downloads/partynextdoor.wav") X = scipy

Integrating 2D data with nans using numpy trapz

I have a 2D matrix U of data that looks something like this: 0 0.5 0.1 0.3 0 nan 0.4 0.1 nan nan 0.2 nan The rows index corresponds to heigh

How to add a new array to an existing npz file in a standard way?

I have a function which writes an array to a compressed *.npz file: def save_a(file): np.savez_compressed(file, a=[[1, 2, 3]]) I want to make a function

Problem with CV2 : numpy.core.multiarray failed to import

Tried to solve it with : pip install -U numpy but it still does not work. That is what the console shows to me when I try to run the application : Runt

Fitting data to numerical solution of an ode in python

I have a system of two first order ODEs, which are nonlinear, and hence difficult to solve analytically in a closed form. I want to fit the numerical solution t

conda install matplotlib results in huge list on incompatibilities

I have a conda env that I build from a requirements.yml file that I obtained from a classmate so we could work on a project together. I tried installing matplot

Concatenate 2 videos into 1 using Python

I want to write a program that monitors and tracks objects in 2 different videos using openCV in python (cv2). I would like to Merge the two videos into 1 vide

Fitting using Chebyshev polynomials in python

I am trying to fit 2d data using polynomial fit and find that after a certain degree of polynomials, numpy gives "Rank Warning". On the other hand, fitting usin