This is continued from this thread: Python matrix, any solution?
Input
from numpy import *
import numpy
x=[[\'1\',\'7\'],
[\'1.5
Convert x
to a numpy array of numbers:
x = numpy.asanyarray([[float(z) for z in y] for y in x])
Edit:
It's not 100% clear to me what you're asking/trying to achieve here. In response to the comment about having [['1','7'] ...]: Currently you have string elements in your list; you can easily enough convert to numeric elements with:
xf = [[float(el) for el in m] for m in x]
Original post: Define your list by putting commas between your list elements:
x=[['1','7'],['1.5', '8'],['2', '5.5'],['2','9']]
When I didn't do this, I got your error, but by doing this I avoided the error.
You are missing commas between the inner lists:
x = [['1', '7'],
['1.5', '8'],
['2', '5.5'],
['2', '9']]
The error message stemmed from Python seeing ['1','7']['1.5','8']
and trying to use the tuple ('1.5','8')
as an index into the list ['1','7']
.