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.]]
Related Resources:
- Save Numpy array to csv file Save Numpy array to csv file Most machine learning engineers and Data Scientists use Numpy array because it’s efficient and...
- Get Numpy array dimensions Find Numpy array dimensions Shape attribute of numpy can be used to find dimensions of numpy array easily. # Imports...
- Numpy Arange Create an Array | Numpy tutorial Numpy Arange Use numpy arange method to create array with sequence of numbers. In the below example we create an...
- Reshape Numpy array | Numpy Tutorial Reshape Numpy Array Reshape numpy array with “reshape” method of numpy library. Reshaping numpy array is useful to convert array...
- Learn Numpy with mini tutorials Numpy Learn Numpy with easy mini tutorials. Numpy is a scientific computing package. Numpy operations are highly optimized therefore handling...
- Reverse Numpy array | Various strategies Reverse Numpy arrays Reverse 1 dimensional numpy arrays using reverse slicing [ : :-1] Reverse N dimensional numpy arrays row wise using...
- Get value from index in Numpy array | Numpy tutorial Value from Index in Numpy Get value from index in numpy array using python like slicing. In below examples we...
- Save Machine Learning model to a file | Pickle Save model to file Save machine learning model so that it can be used again and again without having to...
- Save pandas dataframe to csv or excel file ( 2 Ways to Save pandas dataframe) Save Pandas dataframe to csv and excel file Use “to_csv” and “to_excel” methods to save pandas dataframe to csv and...
- Convert an Array to one dimensional vector Convert an Array to One dimensional Vector | Flatten Convert an Array to One dimensional Vector with flatten method of...