Python Forum

Full Version: Python arrays
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How could I convert my list that is associated with variable data2 to a 2D numpy array?
  • Tell us what you have tried
  • Show an example list
  • If possible show existing code.
  • If errors, show error traceback verbatim
Sorry.

I tried array2 = np.array(data2)
and it eventually worked.
But now i am supposed to convert my data2, which is a list of strings to integers.
I tried
for i in range(len(data2)):
data2[i] = int(data2[i])

and its saying: int() argument must be a string or a number, not 'list'

I am not sure of another way to do this.
It seems that your data2 is not a list of strings but a nested list.

# a list:
data2 = ['1','2','3','4']

# a nested list:
data2 = [['1','2'],['3','4']]