I have to rewrite some Python Code, so that it is compatible with Python 3. Unfortunately one of my files imports Numpy, which isn’t available for Python 3, yet. So I am trying to replace the Numpy-Code with normal Python Code. But I fail to replace Numpy’s reshape-function.
Reshape takes an array as input and reshapes it (changes number of rows/columns). For example:
a = arange(10).reshape(2,5)
creates an array of the form
[[0, 1, 2, 3, 4],
5, 6, 7, 8, 9]
My idea was code like this:
list = range(10)
matrix = []
row = []
for i in range(2):
for j in range 5:
row.append(list[j])
matrix.append(row)
row = []
But nested loops don’t look very nice. Do you know a better way?
The numpy FAQs says that it does not support python 3, but according to the following it does:
http://onpython3yet.com/packages/requirements?r=numpy
You might want to just check to see if your assumption about numpy’s status is correct.