December 2017
Intermediate to advanced
386 pages
10h 42m
English
The savetxt() function admits several parameters, which are useful when we want to output the array in a format that is compatible with a specific application. In this recipe, we show you how to store a NumPy array in CSV format. Comma-separated values (CSV) are used to store tabular data in a text file. Each row of the table is stored in a line of text and elements in each row are separated by a comma. The following code illustrates how to save an array in CSV format:
m, n = 10, 5x = np.random.rand(m, n)columns = ','.join(['Column {}'.format(str(i+1)) for i in range(n)])np.savetxt('array_x.csv', x, fmt='%10.8f', delimiter=',', header=columns, comments='')
With this code, we first generate a 10 x 5 array ...
Read now
Unlock full access