w3resource

NumPy: Convert a NumPy array into a csv file

NumPy: Array Object Exercise-102 with Solution

Write a NumPy program to convert a NumPy array into a csv file.

Sample Solution:

Python Code:

import numpy
data = numpy.asarray([ [10,20,30], [40,50,60], [70,80,90] ])
numpy.savetxt("test.csv", data, delimiter=",")

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to print the full NumPy array, without truncation.
Next: Write a NumPy program to calculate the Euclidean distance.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Set comprehension:

>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}