Python Forum
How to remove apostrophes in a matrix
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to remove apostrophes in a matrix
#5
What I was suggesting is this:
import csv
 
with open('numbers.csv', newline='') as csvfile:
    puzzle=csv.reader(csvfile, delimiter=' ', quotechar='|')
    # Read all the rows so you get
    # matrix = [[0, 0, 9, 0, 0, 0, 5, 6, 2], [0, 0, 0, 9, 0, 0, 0, 0, 0], ...]
    matrix = [row for row in puzzle]

# If now you want to print the matrix
for row in matrix:
    print(', '.join(row))

# Or transform it to integer matrix and not just strings... assuming all the elements are integers.
matrix =[[int(s) for s in row] for row in matrix]
About using eval... avoid it as much as you can. It is useful and powerful, specially when you are a noob but almost anything you can do with eval you can do it better in another way without the risk of explosion (not to mention the huge security problem)
Reply


Messages In This Thread
How to remove apostrophes in a matrix - by sylas - May-06-2018, 12:56 PM
RE: How to remove apostrophes in a matrix - by killerrex - May-06-2018, 05:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if two matrix are equal and of not add the matrix to the list quest 3 867 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  How to multiply a matrix with herself, until the zero matrix results peanutbutterandjelly 3 3,402 May-03-2021, 06:30 AM
Last Post: Gribouillis
  Remove isolated vertices from dictionary and adjacency matrix Weird 1 1,868 Jan-18-2020, 04:33 PM
Last Post: Weird
  remove apostrophes in list sparkz_alot 5 10,077 Jul-21-2017, 09:21 PM
Last Post: sparkz_alot
  Is it possible to avoid apostrophes ? sylas 5 3,862 Jul-19-2017, 11:51 AM
Last Post: Larz60+
  matrix from matrix python numpy array shei7141 1 3,731 Jan-16-2017, 06:10 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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