Visible Deprecation Warning Python

I am trying to make a model in python for an economics dissertation and in calculating a function: elif wage_online == max(wages): # after going to online you get the highest wage after cost of education learning_benefit = i...
more »

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

Generating tall array with numpy

I'm new to python and numpy (I'm more accustomed to R) and have been playing around with creating arrays and want to create a tall array, where the first column is just a range with custom increment, and the second column is a unif random between 0 a...
more »

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

NumPy: calculate cumulative median

I have sample with size = n. I want to calculate for each i: 1 <= i <= n median for sample[:i] in numpy. For example, I counted mean for each i: cummean = np.cumsum(sample) / np.arange(1, n + 1) Can I do something similar for the median wit...
more »

2017-03-13 15:03 (4) Answers

Python: How to return a list of connected nodes

I have a set of nodes (stored as nodes = np.array([[x1,y1],[x2,y2],etc]])) and elements connected the nodes. Each element is an array of the two node indices. So [0,3] is an element connecting nodes 0 and 3. How would I return a list of all node i...
more »

2017-03-08 17:03 (4) Answers

numpy: int is a basestring?

How come numpy numeric types are subtypes of basestring? for nptype in [np.int32, np.int64, np.integer, np.float]: for stype in [str, basestring, unicode]: print nptype, stype, np.issubdtype(nptype,stype) <type 'numpy.int32'> <t...
more »

2017-03-03 00:03 (1) Answers

reshape an array using python/numpy

I want to reshape the following array: >>> test array([ 11., 12., 13., 14., 21., 22., 23., 24., 31., 32., 33., 34., 41., 42., 43., 44.]) in order to obtain: >>> test2 array([[ 11., 12., 21., 22.], ...
more »

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

Python find, extract keyword from list inside loop

I am trying to extract specific keyword from a list but for some reason I get [] empty box or python spits out the whole list which is not what I want. This is the code I have right now. appendxxxx12 = list(appendxxxx12) value0 = list(value0) matc...
more »

2017-03-02 06:03 (2) Answers

Why is Pypy slower for adding numpy arrays?

To test the claims that Pypy JIT is significantly faster I wrote a simple code that repeatedly adds two arrays of size 1200x1200. My code is as follows import numpy as np import random a=np.zeros((1200, 1200), dtype=np.float32) b=np.zeros((1200, 12...
more »

2017-03-01 16:03 (1) Answers

Python: Concatenate 3 arrays

I have theee arrays, and want to combine them import numpy as np a = np.array([[1,2,3],[4,5,6]]) b = np.array([[7,8,9],[10,11,12]]) c = np.array([[13,14,15],[16,17,18]]) To get: array([1,2,3,7,8,9,13,14,15, 4,5,6,10,11,12,16,17,18]) What is the...
more »

2017-02-27 16:02 (1) Answers

Geometric mean applied on row

I have this data frame as example: Col1 Col2 Col3 Col4 1 2 3 2.2 I would like to to add a 4th column called 'Gmean' that calculate the geometric mean of the first 3 columns on each row. How can get it...
more »

2017-02-24 11:02 (2) Answers