How to resolve this equation in python?

I'm trying to resolve this matrix using python: a|b|c d|e|f g|h|i A+B+C=constant D+E+F=constant G+H+I=constant A+D+G=constant B+E+H=constant C+F+I=constant A+E+I=constant C+E+H=constant I have 9 variables + the constants These 9 variables are di...
more »

2017-10-11 15:10 (0) Answers

Selecting every n indices of an array

If I have an array that is 100 elements in length, what is the most Pythonic way to get every n indices. For example, if I wanted every 5 indices of an array a, how could I get an array b=[[0,1,2,3,4],[5,6,7,8,9],[10,11,12,13,14],...], where each el...
more »

2017-10-09 20:10 (3) Answers

Numpy: An efficient way to merge multiple slices

I have a numpy array test_array = np.arange(100).reshape((4,25)) and I want to merge the following cols to form a new array 1:3, 2:4, 3:15, 2:24, 6:8, 12:13 I know this code will work np.hstack((test_array[:,1:3],test_array[:,2:4],test_array[:...
more »

2017-10-09 09:10 (1) 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

Poor performance of C++ function in Cython

I have this C++ function, which I can call from Python with the code below. The performance is only half compared to running pure C++. Is there a way to get their performance at the same level? I compile both codes with -Ofast -march=native flags. I ...
more »

2017-09-29 22:09 (1) Answers

Fastest way to sum over rows of sparse matrix

I have a big csr_matrix(1M*1K) and I want to add over rows and obtain a new csr_matrix with the same number of columns but reduced number of rows. Actually my problem is exactly same as this Sum over rows in scipy.sparse.csr_matrix. The only thing is...
more »

2017-09-28 20:09 (1) Answers

Inconsistent python print output

(Python 2.7.12) - I have created an NxN array, when I print it I get the exact following output: Sample a: SampleArray=np.random.randint(1,100, size=(5,5)) [[49 72 88 56 41] [30 73 6 43 53] [83 54 65 16 34] [25 17 73 10 46] ...
more »

2017-09-27 14:09 (3) Answers

Python 3: RuntimeWarning with numpy.power

When using numpy.power(2,N), where N is an integer, I encounter the following issue: In[1] np.power(2,63) Out[1] -9223372036854775808 RuntimeWarning: invalid value encountered in power and even more strangely, In[2] np.power(2,63)*2 Out[2] 0 Th...
more »

2017-09-18 19:09 (1) Answers

Extracting and transforming data in numpy

Suppose I have the following numpy vector [[1, 3., 'John Doe', 'male', 'doc', '25'], ..., [9, 6., 'Jane Doe', 'female', 'p', '28']] I need to extract relevant to my task data. Being a novice in numpy and python in general, I would do it in t...
more »

2017-09-17 19:09 (1) Answers