Centering of array of images in python

I have an array of images that I want to feed to TensorFlow. I want to center the images around the mean and standardize the standard deviation. I followed this answer but I cannot seem to get the mean to zero. I am learning numpy so maybe I am missi...
more »

2017-01-14 17:01 (1) Answers

Unpacking a list in python using .T?

I'm using scipy's method integrate.odeint to solve a second order LDE. The method requires that the equation be put in the form of a system of two first-order equations in two unknowns. The method odeint(system_matrix,initial_conditions_matrix,time_...
more »

2017-01-14 16:01 (2) Answers

Asigning matrix element by list of tuple keys

I've got a 2dim database as a numpy.array (time,field values). Secondly I have a np.array of tuples, containing the coordinates of the field in the same order. What I want to do now is to reshape the database so that I can later view the map with mat...
more »

2017-01-14 13:01 (1) Answers

Using Scipy curve_fit with piecewise function

I am getting an optimize warning: OptimizeWarning: Covariance of the parameters could not be estimated category=OptimizeWarning) when trying to fit my piecewise function to my data using scipy.optimize.curve_fit. Meaning no fittin...
more »

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

Python: ufloat to float

I have calculated some ufloats using the uncertainties package, let's call them theta and gamma. Now, for my following calculations I don't need their errors (I am using them later as y-values in linear plot). I simply could calculate them ignoring ...
more »

2017-01-13 20:01 (1) Answers

Fastest way to calculate distance

I have a (n, d) dimensional matrix x a (d, L) dimensional matrix c Let's denote the b-th row of x with x_b and the i-th column of c with c_i. I want to calculate the (n, L) dimensional matrix diff which contains at (b, i): || x_b - c_i ||^2, w...
more »

2017-01-13 17:01 (0) Answers

Strange class initialization in Python

In the python library pytides, I came across a strange method to initialize a class (the Tide class and its initialization ). I reproduced below a simplified version of the code : import numpy as np class Foo(object): def __init__(self,x,y): ...
more »

2017-01-13 09:01 (2) Answers

OpenCV ROI background padding

I am trying to focus on a Region of Interest on the face by using Numpy cropping. For large images, I have no trouble. But for smaller ones, I can find the face and find the matching bounding box, but when I try to crop it and show the image, I get a...
more »

2017-01-13 00:01 (0) Answers

Type Error: Positional Arguments with pandas.apply

Problem Statement: A pandas dataframe column series, same_group needs to be created from booleans according to the values of two existing columns, row and col. The row needs to show True if both values have similar values (intersecting values) in a...
more »

2017-01-12 19:01 (2) Answers

How to correctly define numpy dtype

I have such piece of code, where I try to load four columns from csv file import numpy as np rtype = np.dtype([('1', np.float), ('2', np.float), ('3', np.float), ('tier', np.str, 32)]) x1, x2, x3, x4 = np.genfromtxt("../Data/out.txt", dtype=rtyp...
more »

2017-01-12 19:01 (1) Answers

Python: Hierarchical Slicing

Is there a more pythonic/numpythonic way to do some sort of nested/hierarchical slicing, i.e. a prettier version of this: _sum = 0 for i in np.arange(n): _sum += someFunc(A[i,:]) Basically I would like to map someFunc (which takes arrays of any...
more »

2017-01-12 18:01 (2) Answers

Dealing with NaNs in Pandas

I have a dataframe and I want to return a subset (new copy not reference) of this dataframe to perform some operations. However I find it unable to filter on the criteria i need. I need these three criteria to filer : 1. df['A'] != NaN 2. df['B']...
more »

2017-01-12 13:01 (2) Answers

Python: detecting alternates in bipartite graph

I'm looking for either an existing library function from some Python library or a custom Python function using numpy or pandas that is fast, that does the following: takes as input a list of edges in a bipartite graph and returns the subset of the ed...
more »

2017-01-12 04:01 (0) Answers