Intersection of sorted numpy arrays

I have a list of sorted numpy arrays. What is the most efficient way to compute the sorted intersection of these arrays? In my application, I expect the number of arrays to be less than 10^4, I expect the individual arrays to be of length less than ...
more »

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

Random Numbers in a range around a median

I have a median and a standard deviation, what i want is to generate random numbers between the median-std and the median+std. I know how to do it like this: import numpy as np import random as rnd median=30 std=15 random_nr=rnd.randint(median-std...
more »

2017-10-04 15:10 (1) Answers

python , opencv, image array to binary

I have a large image , using cv2 module in python and some coordinates i cropped the image: img = cv.imread(image_path) crop_img = img[y1:y2,x1:x2] cv.imwrite(cropPath, crop_img) now the crop_img is a numpy.ndarray type. then I save this ima...
more »

2017-10-04 13:10 (2) Answers

Python Pandas Data frame creation

I tried to create a data frame df using the below code : import numpy as np import pandas as pd index = [0,1,2,3,4,5] s = pd.Series([1,2,3,4,5,6],index= index) t = pd.Series([2,4,6,8,10,12],index= index) df = pd.DataFrame(s,columns = ["MUL1"]) df["M...
more »

2017-10-04 12:10 (2) Answers

Vectorize numpy code

So I am trying to vectorize this code in numpy and im having trouble Heres is my for loop version which works as desired: B is a 3x3 Matrix for i in range(b.shape[0]): for j in range(b.shape[0]): Z[i,j] = np.sqrt(np.dot((b[i,:].T - b[...
more »

2017-10-04 02:10 (1) Answers

np.dot output incorrect in Jupyter Notebook

I am getting a different result when I run this code in my terminal vs. a Jupyter Notebook. Both are using Python 3.6 and numpy 1.13.1. Terminal (correct solution): >>> import numpy as np >>> vector_one = np.asarray([ ... [1], .....
more »

2017-10-03 22:10 (0) Answers

Flask to Numpy Image Conversion

I have been trying to send an image over javascript to a Flask server to draw bounding boxes on coordinates I received from my own API. How might I convert this to a numpy array? I was thinking of using the cv2.imdecode feature, but I don't want to ...
more »

2017-10-03 21:10 (1) Answers

Create specific array using numpy

I wanted to create this kind of array using numpy: [[[0,0,0], [1,0,0], ..., [1919,0,0]], [[0,1,0], [1,1,0], ..., [1919,1,0]], ..., [[0,1019,0], [1,1019,0], ..., [1919,1019,0]]] To which I can access via: >>> data[25][37] array([25, 37...
more »

2017-10-03 14:10 (2) Answers

keras - TypeError: 'int' object is not iterable

I was trying to test a network, but seem to get an annoying error, which I am not quite sure I understand. import keras from keras.models import Sequential from keras.optimizers import SGD from keras.layers.core import Dense, Activation, Lambda, Re...
more »

2017-10-03 12:10 (1) Answers

pandas: slicing along first level of multiindex

I've set up a DataFrame with two indices. But slicing doesn't behave as expected. I realize that this is a very basic problem, so I searched for similar questions: pandas: slice a MultiIndex by range of secondary index Python Pandas slice multiinde...
more »

2017-10-02 21:10 (1) Answers

Pandas Test Failure

After installing Python 3.6.2 and Pandas on Windows 10 64-bit I ran the test described here. The failures seem to be largely linked to two issues. The first 3 errors have to do with indexing: TestMixedIntIndex.test_argsort & TestMixedIntInde...
more »

2017-10-02 19:10 (1) Answers