Numpy diff inverted operation?

Working with numpy.diff function, suppose this simple case: >>> x = np.array([1, 2, 4, 7, 0]) >>> x_diff = np.diff(x) array([ 1, 2, 3, -7]) How can I get easily x back to original scale not differenced? I suppose there is somet...
more »

2017-04-22 20:04 (1) Answers

Numpy Arrays comparison and indexing

I have 2 arrays of unequal size: >>> np.size(array1) 4004001 >>> np.size(array2) 1000 Now, each element in array2 needs to be compared to all the elements in array1, to find the element which has the nearest value to that of thi...
more »

2017-04-22 06:04 (3) Answers

Tensorflow Create Protobuf for a Tensor

I want to have a Python script that converts Numpy arrays to TensorFlow Tensors in Protobuf Binary so later in C++ I can reload them. This can be done with a compute graph like this. I found the following functions and features in the TensorFlow Pyt...
more »

2017-04-21 22:04 (1) Answers

Reshaping 3D Numpy Array to a 2D array

I have the following 3D array in Numpy: a = np.array([[[1,2],[3,4]], [[5,6],[7,8]], [[9,10],[11,12]],[[13,14],[15,16]]]) when I write b = np.reshape(a, [4,4]) The 2D resulting array will look like [[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 ...
more »

2017-04-21 18:04 (2) Answers

How to merge array into single?

I am trying to transpose this array into single one. My input: a = [[ array([ 3.00514850e+05, 3.32400000e+01, 2.71669002e-01, 6.50974961e+05, 3.00515112e+05, 3.32248995e+01]) array([ 15.])] [ array([ 3.00915200e+05, 2.906000...
more »

2017-04-21 12:04 (1) Answers

Pandas forward cummax

I'd like to find the max possible return in a stock given a series of price data. Given that you can only sell at future price, I think I need to need to put the maximum future price on each row: def maxf(idx): return prc[idx:].bid.max() prc['...
more »

2017-04-21 00:04 (2) Answers

Create large random boolean matrix with numpy

I am trying to create a huge boolean matrix which is randomly filled with True and False with a given probability p. At first I used this code: N = 30000 p = 0.1 np.random.choice(a=[False, True], size=(N, N), p=[p, 1-p]) But sadly it does not se...
more »

2017-04-20 21:04 (3) Answers

Pandas converting date with string in

I'm starting with python and pandas and matplotlib. I'm working with data with over million entries. I'm trying to change the date format. In CSV file date format is 23-JUN-11. I will like to use dates in future to plot amount of donation for each ca...
more »

2017-04-20 18:04 (2) Answers

Numpy: Convert RGB flat array to matrix

I have an array containing the RGB values of all pixels in an image. Supposing a 4x4 image, the array is of size 48, where the first 16 values are the red values, the next 16 are the green and the last 16 are the blue: [r0, r1, ..., r15, g0, g1, ......
more »

2017-04-20 16:04 (1) Answers

Lognormal pdf generates zero in python

I want to generate random numbers from lognormal distribution on background of exponential distribution as folows: I have 100 integers (say localities) from 1 to 25. This integers are generated from my own exponential-like distribution. On this loc...
more »

2017-04-20 14:04 (1) Answers

one hot encode a binary value in numpy

I have a numpy array that looks like the following: array([[0],[1],[1]]) And I want it to be represented as the one hot encoded equivalent: array([[1,0],[0,1],[0,1]]) Any body have any ideas? I tried using sklearn.preprocessing.LabelBinarizer ...
more »

2017-04-20 12:04 (1) Answers

Generate and fill 2 dimensional array with Numpy

I would like to generate a 2 dimensional array with NumPy , iterate some variable few times, and fill the 2 dimensional array with 2 pieces of float data that gets calculated inside the for iteration. Then export it out to .csv Technically I would l...
more »

2017-04-20 05:04 (1) Answers

Select 'some' random points from numpy array

I have two related numpy arrays, X and y. I need to select n random rows from X and store this in an array, the corresponding y value and the appends to it the index of the points randomly selected. I have another array index which stores a list of...
more »

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