How to replace a list of values in a numpy array?

I have an unsorted array of numbers. I need to replace certain numbers (given in a list) with specific alternatives (also given in a corresponding list) I wrote the following code (which seems to works): import numpy as np numbers = np.arange(...
more »

2017-08-17 14:08 (2) Answers

A masked array indexing issue

I have a numpy array with some NaN values: arr = [ 0, NaN, 2, NaN, NaN, 5, 6, 7 ] Using some logic (outside of the question scope), I generate a mask of the NaN locations: mask = [ True, False, True, False, False, True, True, True ] I use this ...
more »

2017-08-17 01:08 (2) Answers

Double dot product with broadcasting in numpy

I have the following operation : import numpy as np x = np.random.rand(3,5,5) w = np.random.rand(5,5) y=np.zeros((3,5,5)) for i in range(3): y[i] = np.dot(w.T,np.dot(x[i],w)) Which corresponds to the pseudo-expression y[m,i,j] = sum( w[k,i] ...
more »

2017-08-16 18:08 (1) Answers

Numpy Array random mutation

I'm coding my first genetic algorithm in Python. I particularly care about the optimization and population scalability. import numpy as np population = np.random.randint(-1, 2, size=(10,10)) Here I make a [10,10] array, with random number between ...
more »

2017-08-16 17:08 (1) Answers

print mismatch items in two array

I want to compare two array(4 floating point)and print mismatched items. I used this code: >>> from numpy.testing import assert_allclose as np_assert_allclose >>> x=np.array([1,2,3]) >>> y=np.array([1,0,3]) >>> np...
more »

2017-08-16 14:08 (1) Answers

Python: Improving Image-processing with numpy

Let there be two big (2000x2000 or higher) .tiff images consisting only of numpy float32 values (no rgb). I call them Image A and B. I want to multiply them in a special way: Find the max value in B and roll it (using numpy.roll) to the upper-left ...
more »

2017-08-16 14:08 (1) Answers

How extract numpy array features from spectrogram?

I created a spectrogram with this code: D = librosa.amplitude_to_db(librosa.stft(y), ref=np.max) librosa.display.specshow(D, y_axis='linear', x_axis='time') plt.colorbar(format='%+2.0f dB') plt.title('Log-frequency power spectrogram') plt.savefig('s...
more »

2017-08-16 10:08 (1) Answers