Select 'some' random points from numpy array

I have two related numpy arrays, X and y. I need to select n random rows from X and store this in an array, the corresponding y value and the appends to it the index of the points randomly selected. I have another array index which stores a list of...
more »

2017-04-20 01:04 (2) Answers

Series sum in python

Is there is a built-in function in python, numpy or one of its libraries can get sum of series like this one: list1 = [2,3,4] list2 = [3,3,3] where x and y are lists and L is the length of x or y. Lastly if there is no built-in function do that...
more »

2017-04-17 19:04 (5) Answers

Loading .npy File Loads an Empty Array

I have a TfIDF matrix of size tr_tfidf_q1.shape, tr_tfidf_q2.shape which gives ( (404288, 83766), (404288, 83766) ) Now I save it using'tr_tfidf_q1.npy', tr_tfidf_q1) When I load the file like this f = np.load('tr_tfidf_q1.npy') f...
more »

2017-04-17 18:04 (2) Answers

Producing spectrogram from microphone

Below I have code that will take input from a microphone, and if the average of the audio block passes a certain threshold it will produce a spectrogram of the audio block (which is 30 ms long). Here is what a generated spectrogram looks like in the...
more »

2017-04-11 20:04 (1) Answers

Vectorizing min and max of slices possible?

Suppose that I have a NumPy array of integers. arr = np.random.randint(0, 1000, 1000) And I have two arrays lower and upper, which represent lower and upper bounds respectively on slices of arr. These intervals are overlapping and variable-length...
more »

2017-04-11 02:04 (3) Answers

Stack Numpy Arrays Without Extra Checks

I have two Numpy arrays labels and more_labels. In one case both arrays are 1D, having shapes (m,) and (n,) in another case both arrays are 2D, having shapes (m,k) and (n,k). I would like to combine them so that the resulting array has shape (m+n,) i...
more »

2017-04-09 07:04 (1) Answers

Code optimization python

I wrote the below function to estimate the orientation from a 3 axes accelerometer signal (X,Y,Z) X.shape Out[4]: (180000L,) Y.shape Out[4]: (180000L,) Z.shape Out[4]: (180000L,) def estimate_orientation(self,X,Y,Z): sigIn=np.array([X,Y,Z]).T ...
more »

2017-04-08 15:04 (1) Answers

Khatri product of matrices using np.tensordot

I'm trying to decompose a Tensor (m, n, o) into matrices A(m, r), B (n, r) and C (k, r). This is known as PARAFAC decomposition. Tensorly already does this kind of a decomposition. An important step is to multiply A, B, and C to get a tensor of sha...
more »

2017-04-06 13:04 (1) Answers

Numpy is calculating wrong

I am using numpy like this code >>>import numpy as np >>>a=np.arange(1,100000001).sum() >>>a 987459712 I guess the result must be some like 5000000050000000 I noticed that until five numbers the result is ok. Does someone knows what is happened? ...
more »

2017-04-04 15:04 (2) Answers

Interpolating a 3d array in Python expanded

My question expands on the code response seen here: Interpolating a 3d array in Python. How to avoid for loops?. Relevant original solution code is below: import numpy as np from scipy.interpolate import interp1d array = np.random.randint(0, 9, size...
more »

2017-04-03 13:04 (0) Answers

how to 3-way outer product in numpy?

About the numpy.outer [link] . Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer product will be M*N matrix. But how to implement a 3-array outer product, which means : given third vector c = [c0, c1, ..., cP], how to...
more »

2017-03-31 22:03 (3) Answers