robust numpy.float64 equality testing

Is there a robust way to test for equality of floating point numbers, or to generally ensure that floats that should be equal actually do equal each other to within the float's precision? For example, here is a distressing situation: >> np.mod...
more »

2017-05-19 21:05 (2) Answers

How to lock down pandas dataframe structure

Simply put, what are the preferred practices for writing larger python applications that use pandas dataframes as its primary method for data representation? I often find myself struggling to maintain inconsistencies in dataframes, sometimes invaria...
more »

2017-05-19 15:05 (0) Answers

Numpy split data with delimiter at once

I have a numpyarray, it looks like this: [ [1,2,6,1,5] [3,6,46] [7,7,6,6,6,62,4] [2,4,52,85,78] ] the data is heterogeneous My question is now if it possible is without doing it for every single row (means no "for loop") to split the data by a de...
more »

2017-05-19 13:05 (2) Answers

Python's fsolve not working

I'm currently trying to find the intercept of 2 equations from my code (pasted below). I'm using fsolve and have used it successfully in one part but I can't get it to work for the second. Confusingly it's not showing up an error, if you paste this...
more »

2017-05-19 11:05 (1) Answers

Loading Image Resource into Numpy Array

I'm trying to get a JPEG image resource from the web into a NumPy array image representation similar to the array returned by scipy.misc.imread. Instead of saving the image to disk, as in the example below: import requests from scipy import misc de...
more »

2017-05-18 22:05 (2) Answers

Tensorflow Reading CSV - What's the best approach

So I've been trying out different ways of reading a CSV file with 97K lines and each line with 500 features (about 100 mb). My first approach was to read all data into memory using a numpy: raw_data = genfromtxt(filename, dtype=numpy.int32, delimit...
more »

2017-05-18 18:05 (1) Answers

How to read JPG2000 with Python?

I have read several JP2 (JPEG200) images with matplotlib and got numpy arrays with big numbers, exceeding 40000. Reading code: img_blue =mpimg.imread('B02.jp2') img_green =mpimg.imread('B03.jp2') img_red =mpimg.imread('B04.jp2') Data is: [[1229...
more »

2017-05-18 17:05 (1) Answers

avoid column slicing array for calculations

import numpy as np Xs = np.array([[1,3,3,4,5,7], [2,4,5,1,1,6], [5,5,6,4,3,2]]).T groupIDs = np.array([10,10,20,20,30,30]) p = np.array([0.5, 0.5, 0.25, 0.75, 1, 0]) _,idx,tags = np.unique(groupIDs, return_index=1, return_inverse=1) print(Xs) [[1 2 5...
more »

2017-05-18 16:05 (2) Answers

How to plot y=1/x as a single graph

Is there an easy way to plot a function which tends to infinity in the positive and negative as a single plot, without the plot joining both ends of the positive and negative? For example, plotting y=1/x using this code gives the resulting plot: i...
more »

2017-05-18 09:05 (3) Answers

Python | Removing mirror pairs in array

In python, I have an array of shape n*2 ( where n is a positive integer ). Essentially, this is an array of pairs. I wish to remove all mirror pairs in this array. For example, the following array A is of shape 10*2. The pairs [0,55] and [55, 0] wou...
more »

2017-05-18 03:05 (4) Answers

append data in a numpy array

I'm trying to pass a list within a numpy array in order to calculate its variance as explained here The example I use is this: import numpy as np A= np.array([]) newrow = [1,2,3] A = np.concatenate((A,newrow)) print(np.var(A)) The example above w...
more »

2017-05-17 13:05 (3) Answers

Difference between array[i][:] and array[i,:]

I'm new to python, so I'm used to use array[i][j] instead of array[i,j]. Today a script I created following a tutorial was not working until I found out that I was using numpy.dot(P[0][:], Q[:][0]) instead of numpy.dot(P[0,:], Q[:,0]) For some ...
more »

2017-05-17 03:05 (2) Answers