Dump a NumPy array into a csv file
Here's an example code snippet that demonstrates how to dump a NumPy array into a CSV file:
Here's an example code snippet that demonstrates how to dump a NumPy array into a CSV file:
Dump a NumPy array into a CSV file in Python
import numpy as np
# Create a NumPy array
data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# Save the array to a CSV file
np.savetxt("data.csv", data, delimiter=",")This will save the array data to a file named data.csv in the current directory. The delimiter parameter specifies that the values in the CSV file should be separated by commas.
You could also use pandas, it's more versatile when working with data
Make csv with pandas DataFrame
import pandas as pd
df = pd.DataFrame(data)
df.to_csv("data.csv",index=False)