Read csv file to numpy array

Use “savetxt” method of numpy to save a numpy array to csv file  

Use “genfromtxt” method to read a csv file into a numpy array 

# Imports 
import numpy as np

# Let's creat a numpy array
nparray = np.array([[1, 2, 4],[1, 3, 9],[1, 4, 16]])

# Saving the array
np.savetxt("firstarray.csv", nparray, delimiter=",")

# Reading the csv into an array
firstarray = np.genfromtxt("firstarray.csv", delimiter=",")

print(firstarray)
[[  1.   2.   4.]
 [  1.   3.   9.]
 [  1.   4.  16.]]