“Python Escribir matriz a archivo” Código de respuesta

convertir la lista de python en archivo de texto

# define list of places
places = ['Berlin', 'Cape Town', 'Sydney', 'Moscow']

with open('listfile.txt', 'w') as filehandle:
    for listitem in places:
        filehandle.write('%s\n' % listitem)
Determined Dunlin

Cómo guardar la lista de Python en el archivo

import json
a = [1,2,3]
with open('test.txt', 'w') as f:
    f.write(json.dumps(a))

#Now read the file back into a Python list object
with open('test.txt', 'r') as f:
    a = json.loads(f.read())
Weary Wombat

Python Escribir matriz a archivo

with open("outfile", "w") as outfile:
    outfile.write("\n".join(itemlist))
Damjan D

Lista de texto Python Python

with open('your_file.txt', 'w') as f:
    for item in my_list:
        f.write("%s\n" % item)
Expensive Eel

Cómo escribir una matriz numpy a un archivo en Python

numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', 
              header='', footer='', comments='# ', encoding=None)


x = y = z = np.arange(0.0,5.0,1.0)
np.savetxt('test.out', x, delimiter=',')   # X is an array
np.savetxt('test.out', (x,y,z))   # x,y,z equal sized 1D arrays
np.savetxt('test.out', x, fmt='%1.4e')   # use exponential notation
Open Ostrich

Respuestas similares a “Python Escribir matriz a archivo”

Preguntas similares a “Python Escribir matriz a archivo”

Más respuestas relacionadas con “Python Escribir matriz a archivo” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código