Saving a Numpy array as an image
I have a matrix in the type of a Numpy array. How would I write it to disk it as an image? Any format works (png, jpeg, bmp...). One important constraint is that PIL is not present. ...
I have a matrix in the type of a Numpy array. How would I write it to disk it as an image? Any format works (png, jpeg, bmp...). One important constraint is that PIL is not present. ...
I'm writing some code (just for fun so far) in Python that will store some data on every point in a 3d space. I'm basically after a 3d matrix object that stores arbitary objects that will allow me to do some advanced selections, like: Get the point where x=1,y=2,z=3. Getting all points where y=2. Getting all points within 3 units of po...
I need to write a function which will detect if the input contains at least one value which is non-numeric. If a non-numeric value is found I will raise an error (because the calculation should only return a numeric value). The number of dimensions of the input array is not known in advance - the function should give the correct value re...
I know there is a simple solution to this but can't seem to find it at the moment. Given a numpy array, I need to know if the array contains integers. Checking the dtype per-se is not enough, as there are multiple int dtypes (int8, int16, int32, int64 ...). ...
In numpy one can use the 'newaxis' object in the slicing syntax to create an axis of length one, e.g.: import numpy as np print np.zeros((3,5))[:,np.newaxis,:].shape # shape will be (3,1,5) The documentation states that one can also use None instead of newaxis, the effect is exactly the same. Is there any reason to choose one over th...
Hello everybody, i'm a pretty new user of python and numpy, so i hope my question won't annoy you. Well, i'd like to calculate the mean of an array in python in this form : Matrice = [1, 2, None] I'd just like to have my None value ignored by the numpy.mean calculation but i can't figure out how to do it. If anybody can help me tha...
I have created a multidimensional array in Python like this: self.cells = np.empty((r,c),dtype=np.object) Now I want to iterate through all elements of my twodimensional array, and I do not care about the order. How do I achieve this? ...
Is it worth my learning NumPy? I have approximately 100 financial markets series, and I am going to create a cube array of 100x100x100 = 1 million cells. I will be regressing (3-variable) each x with each y and z, to fill the array with standard errors. I have heard that for "large matrices" I should use NumPy as opposed to Python lis...
I have this line of code in MATLAB, written by someone else: c=a.'/b I need to translate it into Python. a, b, and c are all arrays. The dimensions that I am currently using to test the code are: a: 18x1, b: 25x18, ...
I have this line of code: a/b I am using these inputs: a=[1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9] b=ones(25,18) this is the result: [5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], a 1x25 matrix. what is matlab doing? I am trying to duplicate this behavior in Python, and the mrdivide documentation in matlab was unhelpful. where d...
This should be easy. here's my array (rather, a method of generating representative test arrays): >>> ri = numpy.random.randint >>> ri2 = lambda x: ''.join(ri(0,9,x).astype('S')) >>> a = array([float(ri2(x)+ '.' + ri2(y)) for x,y in ri(1,10,(10,2))]) >>> a array([ 7.99914000e+01, 2.08000000e+01, 3.94000000e+02, 4.661000...
Is there a better way to find which X gives me the Y I am looking for in SciPy? I just began using SciPy and I am not too familiar with each function. import numpy as np import matplotlib.pyplot as plt from scipy import interpolate x = [70, 80, 90, 100, 110] y = [49.7, 80.6, 122.5, 153.8, 163.0] tck = interpolate.splrep(x,y,s=0) xnew =...
Numpy is an extremely useful library, and from using it I've found that it's capable of handling matrices which are quite large (10000x10000) easily, but begins to struggle with anything much larger (trying to create a matrix of 50000x50000 fails). Obviously, this is because of the massive memory requirements. I was wondering if there ...
Hi all. I am new to Python and Numpy, and I am facing a problem, that I can not modify a numpy.recarray, when applying to masked views. I read recarray from a file, then create two masked views, then try to modify the values in for loop. Here is an example code. import numpy as np import matplotlib.mlab as mlab dat = mlab.csv2rec(args...
I want to use some Python libraries to replace MATLAB. I'd like to know how could I import excel data in Python (for example using numpy) to use them. I don't know if Python is a credible alternative to MATLAB, but I want to try it. If you have any tutorial I'd be glad to read it! Thanks a lot! ...
In a pylab program (which could probably be a matlab program as well) I have a numpy array of numbers representing distances: d[t] is the distance at time t (and the timespan of my data is len(d) time units). The events I'm interested in are when the distance is below a certain threshold, and I want to compute the duration of these even...
Is there a FFT-based 2D cross-correlation or convolution function built into scipy (or another popular library)? There are functions like these: scipy.signal.correlate2d - "the direct method implemented by convolveND will be slow for large data" scipy.ndimage.correlate - "The array is correlated with the given kernel using exact calcu...
I've been recently wondering about the over-proliferation of DSLs like R - and thinking whether this is good or bad. Specifically, I wonder what right has R as a stand-alone language and environment? Wouldn't it be much better to build it as an internal DSL/library on some popular language (like Python)? What can R do that Python with s...
Hi I'm using cython for a correlation calculation in my python program. I have two audio data sets and I need to know the time difference between them. The second set is cut based on onset times and then slid across the first set. There are two for-loops: one slides the set and the inner loop calculates correlation at that point. This m...
Hi, I have a set of data's as, Table-1 X1 | Y1 ------+-------- 0.1 | 0.52147 0.02 | 0.8879 0.08 | 0.901 0.11 | 1.55 0.15 | 1.82 0.152 | 1.95 Table-2 X2 | Y2 -----+------ 0.2 | 0.11 0.21 | 0.112 0.34 | 0.120 0.33 | 1.121 I have to interpolate Table-2 'Y2' value f...