9951 explained code solutions for 126 technologies


python-numpyHow to save Numpy array to CSV


import numpy as np
a = np.array([1, 2, 3, 4, 5])
np.savetxt('/tmp/numpy.csv', a)ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

.savetxt(

save given Numpy array into CSV file


Usage example

import numpy as np
a = np.array([1, 2, 3, 4, 5])
np.savetxt('/tmp/numpy.csv', a)

with open('/tmp/numpy.csv', 'r') as f:
  print(f.read())
output
1.000000000000000000e+00
2.000000000000000000e+00
3.000000000000000000e+00
4.000000000000000000e+00
5.000000000000000000e+00