long arrays storing in file python

Solutions on MaxInterview for long arrays storing in file python by the best coders in the world

showing results for - "long arrays storing in file python"
Paola
10 Jan 2017
1# long arrays can be stored in csv files far more efficiently
2import numpy as np
3import csv
4
5# uploading arrays in a csv file
6arr1 = [i for i in range(500)]
7arr2 = [i for i in range(1000)]
8arr3 = [i for i in range(2000)]
9# you can write('w') or append('a')
10with open('record.csv', 'a') as record_append:
11    np.savetxt(record_append, np.asarray([arr1]), delimiter=',')
12    np.savetxt(record_append, np.asarray([arr2]), delimiter=',')
13    np.savetxt(record_append, np.asarray([arr3]), delimiter=',')
14
15# downloading them from the csv file
16two_dim_arr = []  # each line of the file is an array element
17with open('record.csv', 'r') as record_read:
18    reader = csv.reader(record_read)
19    for i, each_arr in enumerate(reader):
20        two_dim_arr.append([eval(each) for each in each_arr])
21        
22# printing the arrays in lines
23for each_line in two_dim_arr:
24  print(each_line)
queries leading to this page
write and read list to file pythonhow to read list in filearray list python with data in filehow to read a list from file in pythontwo list save in db in pythonhow to save an array as csv file in pythonread csv file and create arraysstore array in file and read pythonhow to convert augmented data into csv file using pythonpython save list content securelyexport csv file python from an arraypython store array in filewrite list text file pythonpython script that reads from a listwrite numpy array in file how to store list information in a file pythonread csv file and create arrays pythonwhy the output of a csv is an array in pythonstore numpy array in filesave array information in a file pythonreading a list with for in pythonpython write and read array to filepython read and write array to filepython write and read array from filestoring values from a file as a string in a list pyhtonpython read list filehow do you read a file and store it to an array in pythonhow to store the line information as list in pythonread all file and store in an array using pythonwrite array of string to file pythonread and write in array in file pythonsaving arrays in file txt pythonformat like a list when writing to text file pythonarray storing in file by pythonpython array to csv filestore the list in text file in pythonread and write text file to list pythonput csv file as np arraynumpy array save in filestore file in array pythonhow to read a list of numbers in a text file and input it into a list in pythonpython script to get data and save it as a listpythonwrite array to filehow to store an array in a file in pythonwrite all in array to file pythonpython write array of strings to filelong arrays storing in file python