Python Forum
Convert element of list to integer(Two dimentional array)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert element of list to integer(Two dimentional array)
#2
You need to transform each row first to integer, either when you read the values:
for i in range(r):
    row = input("Row values:")
    m.append([int(s) for s in row.split()])
Or later:
m = [[int(s) for s in row] for row in m]
Remember that numpy only transforms a matrix given as a list of lists to a 2D array if all the lists have the same number of elements, so you might want to use the c value that you are not using to guarantee that the user inputs the right number of elements (or to add 0 or truncate as needed)
Reply


Messages In This Thread
RE: Convert element of list to integer(Two dimentional array) - by killerrex - Jun-11-2018, 08:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Turn list of arrays into an array of lists Cola_Reb 6 1,762 Jul-20-2022, 06:55 PM
Last Post: Cola_Reb
  numpy 2-dimentional rwahdan 3 2,142 Sep-21-2021, 07:40 PM
Last Post: deanhystad
  RandomForest --ValueError: setting an array element with a sequence JaneTan 0 1,766 Sep-08-2021, 02:12 AM
Last Post: JaneTan
  convert a list of string+bytes into a list of strings (python 3) pacscaloupsu 4 10,924 Mar-17-2020, 07:21 AM
Last Post: markfilan
  I am trying to change the value of an element in a record array ingu 1 2,206 Jan-14-2020, 01:30 PM
Last Post: perfringo
  TensorFlow get error - array with more than one element is ambiguous vokoyo 3 5,590 Nov-07-2019, 01:12 PM
Last Post: ThomasL
  How convert multidimensional array to two dimensional array tkkhan44 1 2,802 Feb-20-2019, 05:00 AM
Last Post: scidam
  How to add an element such as an average to a multi-dimensional array? xhughesey 6 4,065 Jan-06-2019, 10:47 PM
Last Post: xhughesey
  ValueError: The truth value of an array with more than one element is ambiguous. Eliza5 1 14,376 Apr-02-2018, 12:03 AM
Last Post: scidam
  Importing matlab cell array (.mat) into a python list scanato 0 8,690 Nov-15-2017, 11:04 AM
Last Post: scanato

Forum Jump:

User Panel Messages

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