Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

inporting csv file however integers appearing as floating points

Hi I'm trying to import a csv file to create an adjacency matrix to then plat a directed graph. I've uploaded the csv file and then used this code to generate the matrix

sage: import csv
sage: data = list(csv.reader(file(DATA+'matrix23.csv'))) sage: m = matrix([[ float(_) for _ in line] for line in data]) sage: m

However although my csv file only contains integers 1's and 0's. the generated matrix is floating point 1.0's and 0.0's. This then causes problems trying to create the graph. The CSV file was created using MS Excel with cells formated to zero decimal places.

I'm new to both python and sage and can't find anything on the forums to help

inporting csv file however integers appearing as floating points

Hi I'm trying to import a csv file to create an adjacency matrix to then plat plot a directed graph. I've uploaded the csv file and then used this code to generate the matrix

sage: import csv 
sage: data = list(csv.reader(file(DATA+'matrix23.csv'))) sage: m = matrix([[ float(_) for _ in line] for line in data]) sage: m

m

However although my csv file only contains integers 1's and 0's. the generated matrix is floating point 1.0's and 0.0's. This then causes problems trying to create the graph. The CSV file was created using MS Excel with cells formated to zero decimal places.

I'm new to both python and sage and can't find anything on the forums to help

inporting import csv file however file: integers appearing as floating points

Hi I'm Hi,

I am trying to import a csv file in order to create an adjacency matrix to and then plot a the associated directed graph. I've uploaded I upload the csv file and then used this code use its content to generate the a matrix as follows

sage: import csv                           
sage: data = list(csv.reader(file(DATA+'matrix23.csv')))
sage: m = matrix([[ float(_) for _ in line] for line in data])
sage: m

However although Whereas my csv file only contains integers 1's and 0's. 0's, the generated matrix is floating point 1.0's and 0.0's. This then causes problems trying to create 0.0's!

Note: the graph. The CSV file was created using MS Excel with cells formated to zero decimal places.

I'm new to both python and sage and can't find anything on the forums to help