Convertir de CSV a array en Python

Tengo un archivo CSV que contiene lo siguiente.

0.000264,0.000352,0.000087,0.000549 0.00016,0.000223,0.000011,0.000142 0.008853,0.006519,0.002043,0.009819 0.002076,0.001686,0.000959,0.003107 0.000599,0.000133,0.000113,0.000466 0.002264,0.001927,0.00079,0.003815 0.002761,0.00288,0.001261,0.006851 0.000723,0.000617,0.000794,0.002189 

Quiero convertir los valores en una matriz en Python y mantener el mismo orden ( fila y columna ). ¿Cómo puedo lograr esto?

He intentado diferentes funciones pero terminé con error.

Deberías usar el módulo csv :

 import csv results = [] with open("input.csv") as csvfile: reader = csv.reader(csvfile, quoting=csv.QUOTE_NONNUMERIC) # change contents to floats for row in reader: # each row is a list results.append(row) 

Esto da:

 [[0.000264, 0.000352, 8.7e-05, 0.000549], [0.00016, 0.000223, 1.1e-05, 0.000142], [0.008853, 0.006519, 0.002043, 0.009819], [0.002076, 0.001686, 0.000959, 0.003107], [0.000599, 0.000133, 0.000113, 0.000466], [0.002264, 0.001927, 0.00079, 0.003815], [0.002761, 0.00288, 0.001261, 0.006851], [0.000723, 0.000617, 0.000794, 0.002189]] 

El módulo csv fue creado para hacer precisamente esto. La siguiente implementación del módulo se toma directamente de los documentos de Python .

 import csv with open('file.csv','rb') as csvfile: reader = csv.reader(csvfile, delimiter=',', quotechar='|') for row in reader: #add data to list or other data structure 

El delimitador es el carácter que separa las entradas de datos, y el quotechar es el quotechar.

Si tu archivo no contiene paréntesis

 with open('input.csv') as f: output = [float(s) for line in f.readlines() for s in line[:-1].split(',')] print(output);