I have a file that looks something like this: some text the grids are 3 x 3 more text matrix marker 1 1 3 2 4 7 4 2 9 1 1 new matrix 2 4 9 4 1 1 3 4 4 3 1 new matrix 3 3 7 2 1 1 3 4 2 3 2 .. the file continues, with several 3x3 matrices appearing in

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

I would like to convert any string (a number with units) to a float. I have a list of values like myList = ["$800", "0.1mm", "54.6%", "100,000,000", "89.6", "1,017.16%"] And I would like to conve

Let's say I've initialized a matrix/array that has 400 rows, 3 columns: distances = np.zeros([400, 3], dtype=np.float64) Now, I have a for loop that returns 1200 objects (float values) and I want to "append" each element into distances (row by r

Say I have an MxN matrix of 0's and 1's. It may or may not be sparse. I want a function to efficiently find rectangles in the array, where by rectangle I mean: a set of 4 elements that are all 1's that create the 4 corners of a rectangle, such that t

This question is close to what is asked in Overriding other __rmul__ with your class's __mul__ but I am under the impression that this is a more general problem then only numerical data. Also that is not answered and I really don't want to use the ma

Let's say I have a 1D numpy array x and another one y = x ** 2. I am looking for an easier alternative to for i in range(x.size): print(x[i], y[i]) With one array one can do print(*x, sep = '\n') which is easier than a for loop. I'm thinking of somet

Something is wrong in my script and I found the error, but I'm completely stuck. there is array b which contains two elements: b = np.zeros ((1,2)) b[0,0] = 272 b[0,1] = 1578 I want to check if there are elements in the second columns, greater than a

I want to append a numpy array(matrix) into an array through a loop data=[[2 2 2] [3 3 3]] Weights=[[4 4 4] [4 4 4] [4 4 4]] All=np.array([]) for i in data: #i=[2 2 2 ] #for example h=i*Weights #h=[[8 8 8][8 8 8][8 8 8]] All=np.concatenate((All,h),ax

Ok, I'm sure there is a very easy way to do this, but I'm rusty in python and I can't work out the pythonic way to do this. I have a list, representing the hours of the day: import numpy as np hourOfDay = np.mod(range(0, 100), 24) Then I want to crea

I am using a recurrent neural network to consume time-series events (click stream). My data needs to be formatted such that a each row contains all the events for an id. My data is one-hot encoded, and I have already grouped it by the id. Also I limi

I have a multiprocessing job where I'm queuing read only numpy arrays, as part of a producer consumer pipeline. Currently they're being pickled, because this is the default behaviour of multiprocessing.Queue which slows down performance. Is there any

I must translate some Matlab code into Python 3 and I often come across ranges of the form start:step:stop. When these arguments are all integers, I easily translate this command with np.arange(), but when some of the arguments are floats, especially

I'm quite new to python world. Also, I'm not a statistician. I'm in the need to implementing mathematical models developed by mathematicians in a computer science programming language. I've chosen python after some research. I'm comfortable with prog

Skip to Update 2 below, if you don't want to read too much background. I'm trying to implement a model for simple orbital simulations (two body). However, when I try to use the code I've written, the plots generated from the result look quite odd. Th

numpy has three different functions which seem like they can be used for the same things --- except that numpy.maximum can only be used element-wise, while numpy.max and numpy.amax can be used on particular axes, or all elements. Why is there more th

I have a big text file which is an output of some codes and it contains lists of numbers. The format of the lists in the file is as following [ 11.42102518 3.3538624 231.82137052 352.12777653] [ 12.68274035 2.84982539 292.99135783 331.74058558] [ 11.

I have following function: def get_denom(n_comp,qs,x,cp,cs): ''' len(n_comp) = 1 # number of proteins len(cp) = n_comp # protein concentration len(qp) = n_comp # protein capacity len(x) = 3*n_comp + 1 # fit parameters len(cs) = 1 ''' k = x[0:n_comp]

I use numpy and have two arrays, which are read with genfromtxt. They have the shape <10000,> according to np.shape(). I want these two vectors to be in an array with the shape <10000,2>. For now I use: x = zip(x1,x2) but i am not sure if ther

I'm reading data (numbers) from a file into a list, as follows: weight_file = open(model_name, 'r').readlines() weights = weight_file[6:] It seems that I can't read them straight into a numpy.array because the first rows of the file contains words. S

I am using defaultdict to store millions of phrases, so my data structure looks like mydict['string'] = set(['other', 'strings']). It seems to work ok for smaller sets but when I hit anything over 10 million keys, my program just crashes with the hel

Using numpy or itertools is there a efficient way to determine the distance to next non-consecutive elements. > import numpy as np > a=np.array(['a','b','b','c','d','a','b','b','c','c','c','d']) I would want the output to be. [1, 2, 1, 1, 1, 1, 2, 1

I want to generate a numpy array of the form: 0.5*[[0, 0], [1, 1], [2, 2], ...] I want the final array to have a dtype of numpy.float32. Here is my attempt: >>> import numpy as np >>> N = 5 >>> x = np.array(np.repeat(0.5*np.aran

When I am trying to build matplotlib-1.3.1, I am getting the below freetype header errors. Probably it is not finding the ftheader.h. Any idea on how to solve this problem? NOTE: I just installed Freetype-2.5.0.1 following the instructions as mention

In my program I current create a numpy array full of zeros and then for loop through each element replacing it with the desired value. Is there a more efficient way of doing this? Below is an example of what I am doing however, instead of a int I hav

I have the code: def find_zeros(data): '''creates a list of the indexes of the zeros in the data''' zeroidx=np.where(np.any(data==0, axis=1)) print zeroidx return len(zeroidx) But the result is: (array([525, 526, 527, 528, 529, 530, 531, 532, 533, 53

I am trying to reproduce this Mathematica program in Python: It finds the roots of an numerical integration, and forms a plot of these values. However, I cannot get my attempt to run. Current attempt: from scipy.integrate import quad from scipy impor

I want to calcuate the eucledian distance in multiple dimensions (24 dimensions) between 2 arrays. I'm using Numpy-Scipy. Here is my code: import numpy,scipy; A=numpy.array([116.629, 7192.6, 4535.66, 279714, 176404, 443608, 295522, 1.18399e+07, 7.742

I want to get the intersecting (common) rows across two 2D numpy arrays. E.g., if the following arrays are passed as inputs: array([[1, 4], [2, 5], [3, 6]]) array([[1, 4], [3, 6], [7, 8]]) the output should be: array([[1, 4], [3, 6]) I know how to do

What is a good way to bin numerical values into a certain range? For example, suppose I have a list of values and I want to bin them into N bins by their range. Right now, I do something like this: from scipy import * num_bins = 3 # number of bins to