0
votes
2answers
40 views

Check between which floats in a list a given float falls

I have a list that looks like this: # Ordered list. a = [0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9] I need to iterate through a list of floats that looks like this: # Not ordered list. b = [0.12, 0.53, ...
0
votes
1answer
20 views

Create 2D array from where clause on 1D array numpy

I have a 1D array containing integer values: a = np.array([1,2,3,3,2,2,3,2,3]) a array([1, 2, 3, 3, 2, 2, 3, 2, 3]) I would like to create a 2D array with the first dimension holding the index of ...
1
vote
2answers
25 views

Memory Error with numpy on several large arrays

So I am trying to carry out the following calculations on a series of large arrays but I keep getting the error: MemoryError In total there are 9 grain_size arrays 2745 by 2654 (Note: I could use ...
1
vote
2answers
40 views

Drawing the same random numbers in numpy

I got the following piece of code: import numpy as np rand_draw1 = np.random.rand(5,4) rand_draw2 = rand_draw1 rand_draw2[0:2,0:4] = np.random.rand(2,4) My intention is to have the variables ...
0
votes
2answers
26 views

How to Mask an image using Numpy/OpenCV?

I have an image I load with: im = cv2.imread(filename) I want to keep data that is in the center of the image. I created a circle as a mask of the area I want to keep. I created the circle with: ...
2
votes
1answer
26 views

grouping table elements according to grouping column values

I have this table, with number of photon counts of an event in each energy channel. The third column is the grouping of the channel: all the channel marked with -1 are grouped into one single ...
-1
votes
1answer
19 views

Filter pandas Dataframe based on max values in a column

I have a DataFrame with repeating values in the index. I would like to filter this dataset down to only show me one instance of each index by selecting the row within the index with the greatest value ...
2
votes
1answer
19 views

Obtain one number from numpy subarrays of size 2 given its peer

I have a array with pairs of numbers (subarrays of size 2) like this: pairs = np.array([[1, 2],[5, 12],[9, 33],[9, 1],[34,7]]) and the peers array, like this: nums = np.array([1,12,9]) What I ...
0
votes
0answers
34 views

percentiles from counts of values

I want to calculate percentiles from an ensemble of multiple large vectors in Python. Instead of trying to concatenate the vectors and then putting the resulting huge vector through numpy.percentile ...
1
vote
1answer
16 views

Python OpenCV (cv2) VideoCapture.read() Unspecified error in NumpyAllocator::allocate

I am new to OpenCV and I am using the python version of it to read out the frames of a video so that I can do some analysis on them. I am reading an mp4 video file and looping through the frames to ...
1
vote
3answers
25 views

numpy array print index of certain value

Given a numpy array A = np.array([[[29, 64, 83], [17, 92, 38], [67, 34, 20]], [[73, 28, 45], [19, 84, 61], [22, 63, 49]], ...
0
votes
0answers
27 views

What scipy statistical test do I use to compare sample means?

Assuming sample sizes are not equal, what test do I use to compare sample means under the following circumstances (please correct if any of the following are incorrect): Normal Distribution = True ...
0
votes
3answers
53 views

Python: How to pass a generator to a function?

Quick description: You can probably work out what I want to do by looking at this (broken) snippet: numpy.savez('tmp.npz',range(i) for i in range(2,100)) I'd rather not have some work-around like: ...
0
votes
2answers
23 views

repeat array in arbitary length

Is it possible to create an array that looks like 0, 1, 2, 3, 0, 1, 2, 0, 1, 2, 3, 4, 0, 1 having the following array in the beginning 4, 3, 5, 2 without using loops in Python/Numpy? EDIT: ...
0
votes
1answer
18 views

Using numpy dstack elementwise?

I'm aware that dstack can do this: array([0, 1, 2]) array([3, 4, 5]) to: array([[[0,3], [1,4], [2,5]]] But I want this without looping: array([[[0,3], [0,4], ...
0
votes
1answer
38 views

Is there a faster way to search a numpy array

I have a numpy array of roughly 3125000 entries the data is structured using the following dtype dt = np.dtype([('startPoint', '<u8' ), ('endPoint', '<u8')]) The data is from a file that has ...
0
votes
2answers
40 views

Python - Bilinear image interpolation

I'm trying to write a Python function that takes an image as input and performs bilinear image interpolation to resize an image. I've had reasonable success, since the image does get resized, but the ...
0
votes
2answers
38 views

Determine sum of numpy array while excluding certain values

I would like to determine the sum of a two dimensional numpy array. However, elements with a certain value I want to exclude from this summation. What is the most efficient way to do this? For ...
0
votes
1answer
22 views

Normalization of several time-series of different lengths and scale

Say I have several random time-series in numpy, e.g.: my_time_series = dict() for L in range(20,50,10): scaling = np.random.randint(100) my_time_series[L] = scaling * np.random.rand(L) + ...
2
votes
1answer
46 views

Merge dictionaries with key combinations

I have two dictonaries A and B and both have the same keys a, b and value. All 3 values of behind those keys are numpy arrays of the same size, but the size may differ between A and B. If found this ...
-1
votes
3answers
35 views

Numpy array construction using tuples

C = numpy.array([a^b for a,b in A,B]) Is what I attempted. I thought it would xor each individual element in A and B which are matrices of their own and store it as the same shape within C. How ...
0
votes
1answer
33 views

Convert to Web Mercator With Numpy

My program vertically stretches a Numpy array, representing a 180 by 360 map image, so it represents a Web Mercator map image. I wrote a function (below) that does what I want - but it is crazy slow ...
1
vote
0answers
20 views

Defining a function with a loop in Theano

I want to define the following function of two variables in Theano and compute its Jacobian: f(x1,x2) = sum((2 + 2k - exp(k*x1) - exp(k*x2))^2, k = 1..10) How do I make a Theano function for the ...
0
votes
4answers
44 views

Get the mean across multiple Pandas DataFrames

I'm generating a number of dataframes with the same shape, and I want to compare them to oneanother. I want to be able to get the mean and median accross the dataframes. Source.0 Source.1 ...
1
vote
1answer
18 views

runtimewarning while using lagrange interpolation in numpy

I am trying to implement lagrange interpolation on a time series. My input is in below format which contains two columns datetime and stock value '3/8/2012 16:00:00 32.21' '3/9/2012 16:00:00 32.16' ...
2
votes
2answers
47 views

Producing an array from an ellipse

I have an equation that creates an ellipse in the general form x^2/a^2 + y^2/b^2 = 1. I wish to produce an array whereby all points inside the ellipse are set to one and all points outside are a zero. ...
0
votes
1answer
13 views

Display numpy ndarray in wxpython

I want to display a numpy ndarray in wxpython but somehow I can't get it to work... My image control: self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(img)) My image ...
1
vote
2answers
93 views

Python with Numpy/Scipy vs. Pure C++ for Big Data Analysis

Doing Python on relatively small projects makes me appreciate the dynamically typed nature of this language (no need for declaration code to keep track of types), which often makes for a quicker and ...
0
votes
1answer
14 views

Does marching cubes in vtk require specific input?

The marching cubes class does not generate anything after I passed a ImageData to it. I am trying to generate surface from a 3D numpy array. I used evtk to export the array to a .vti (Structured ...
-1
votes
1answer
45 views

Weighted Linear Regression with Numpy [on hold]

I need to perform weighted linear regression using numpy. I have all the data points and so I can easily obtain standard deviations or other measures of uncertainty as needed. I had been using ...
1
vote
3answers
60 views

Python NUMPY HUGE Matrices multiplication

I need to multiply two big matrices and sort their columns. import numpy a= numpy.random.rand(1000000, 100) b= numpy.random.rand(300000,100) c= numpy.dot(b,a.T) sorted = [argsort(j)[:10] for j ...
0
votes
1answer
32 views

numpy.ndarray.shape changing dimension

The tuple holding the dimensions of a numpy array (numpy.ndarray.shape) changes size. E.g: len(numpy.array([1,2,3]).shape) -> 1, shape=(1,) len(numpy.array([[1,2,3],[4,5,6]]).shape) -> 2, ...
1
vote
1answer
25 views

How to stack multiple Astropy Tables

I have a for loop that generates several variables let say a, b, and c. I would like to vertically stack the variables after the for loop gone trough the loops. Here what I would like to do. (let say ...
0
votes
1answer
32 views

Python ARIMA exogenous variable out of sample

I am trying to predict a time series in python statsmodels ARIMA package with the inclusion of an exogenous variable, but cannot figure out the correct way to insert the exogenous variable in the ...
0
votes
1answer
43 views

Finding linearly interdependent columns of a matrix in numpy

Problem: I have an MxN matrix where M>=N. I want to identify the groups of linearly-interdependent column-vectors within this matrix. I'm hoping there's a fast and easy way to do this in numpy. ...
1
vote
1answer
34 views

Draw lines-points graph

I have: a list of Q NODES = [(x, y)_1, ........, (x, y)_Q], where each element (x, y) represents the spatial position of a node in 2D Cartesian space. a QxQ matrix H, where H[k, l] is the length of ...
1
vote
3answers
63 views

How to declare and fill an array in python?

I am new to python syntax not new to programing. I need to create an empty array in python and fill it in a loop method. data1 = np.array([ra,dec,[]]) Here is what I have. The ra and dec portions ...
0
votes
0answers
30 views

plotting a contourf graph with maplotlib [on hold]

I'm using the "contourf" method to plot a 2D array that was extracted from an excel sheet. But i want the 'Z' axis (the one depicted by colors) to be my Y axis and my Y axis to be my 'Z' axis, in ...
-3
votes
0answers
17 views

R/Python: kernlab::ipop equivalent in Python [on hold]

I am looking for an implementation of the LOQO quadratic programming method a la Vanderbei (1999) in Python. I am rewriting some R library in Python which uses this method implemented as the function ...
3
votes
0answers
32 views

Scipy ndimage morphology operators saturate my computer memory RAM (8GB)

I need to compute morphological opening for 3D array of shape (400,401,401), size 64320400 bytes using a 3D structure element with a radius of 17 or greater. The size of structure element ndarray is ...
0
votes
1answer
29 views

How do I calculate expected values of a Poisson distributed random variable in Python using Scipy?

I want to calculate an expected value of a function of a Poisson distributed random variable using Scipy. import scipy.stats as stats from scipy.stats import poisson, norm G = poisson(mu=30) ...
1
vote
1answer
14 views

How to create of Numpy array of datetime64 objects using C API?

I need to create an array of numpy datetime64 objects from C/C++ code. As you can see for NPY_LONGLONG and NPY_VOID I did it. I need to do the same thing for NPY_DATETIME type. PyObject *arr1 = ...
1
vote
1answer
35 views

Multiple processes sharing a single Joblib cache

I'm using Joblib to cache results of a computationally expensive function in my python script. The function's input arguments and return values are numpy arrays. The cache works fine for a single run ...
1
vote
1answer
38 views

Python numpy array calculation

I have calculated a histogram slice using numpy histogram by N,a = np.histogram(z,bins=50). Now my a contains the values of the 50 slices of z and N contains the number counts within those slices. ...
1
vote
3answers
44 views

add string to the end of a letter python

How can I do the following in python; for i in range(4): s_i = 3 so I get s_0 = 3 s_1 = 3 s_2 = 3 s_3 = 3
0
votes
2answers
30 views

Comparing equality between sum and constant

I have the following code snippet ... try: assert(float(elem[0]+elem[1])==1.0) except AssertionError: print float(elem[0]+elem[1]), elem[0]+elem[1] ... where elem is a two element numpy ...
-1
votes
1answer
48 views

using numpy to read a file into python

So this might be a bit of a noob question as I don't have a whole lot of python experience. I have a .dat file that I've converted into .csv that I'm trying to read into python. This should be very ...
2
votes
3answers
37 views

Comparing a numpy array object to multiple conditions

I am trying to use numpy.where to find the indices I want. Here's the code: import numpy as np a = np.array([20,58,32,0,107,57]).reshape(2,3) item_index = np.where((a == 58) | (a == 107) | (a == 20)) ...
0
votes
3answers
22 views

Removing nan elements from matrix

I have a bunch of matrices eq1, eq2, etc. defined like from numpy import meshgrid, sqrt, arange # from numpy import isnan, logical_not xs = arange(-7.25, 7.25, 0.01) ys = arange(-5, 5, 0.01) x, y = ...
0
votes
4answers
32 views

Simpler way to create a matrix/list of indices?

I wonder what could be the easiest way to create a bi-dimensional array, that has for each row the indices to another multi-dimensional array. For example, let's say I have a cube 4x4, the "indices ...