Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python arrays
#1
How could I convert my list that is associated with variable data2 to a 2D numpy array?
Reply
#2
  • Tell us what you have tried
  • Show an example list
  • If possible show existing code.
  • If errors, show error traceback verbatim
Reply
#3
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.
Reply
#4
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']]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: only size-1 arrays can be converted to Python scalars RainbowTrish1 1 3,020 Oct-29-2020, 06:16 PM
Last Post: DeaD_EyE
  Fixing arrays output in Python WLST script pkbash 2 3,986 Feb-28-2019, 06:20 PM
Last Post: pkbash

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020