Difference makes the DIFFERENCE
import numpy as np
planets_small = np.loadtxt("planets_small.txt")
planets_small = np.loadtxt("planets_small.txt", skiprows=1)
planets_small = np.loadtxt("planets_small.txt",
skiprows = 1,
usecols = (1,2,3,4,5,6,7,8,9))
planets_small
planets_small.ndim
planets_small.shape
planets = np.loadtxt("planets.txt", skiprows = 1,
usecols = (1,2,3,4,5,6,7,8,9))
planets = np.genfromtxt("planets.txt", skip_header = 1,
usecols = (1,2,3,4,5,6,7,8,9))
planets #the previous conversion error "UNKNOWN" is taken care here and
#doesnot return error.
planets.shape
planets.isnan()
np.isnan(planets) # returns false where ever there is an nan
to convert "NAN" to numpy readable formats or other chosen value => here as -1
planets_new = np.nan_to_num(planets, nan=-1)
planets_new
Save into a file into a human readable format
np.savetxt('planets_new.txt', planets_new, delimiter=",")
np.save("planets_new", planets_new)
list files in the default container with ls command with ! command - to run native unix commands
!ls
!ls -l
!ls -lh
to store multiple arrays in the same file
arr1 = np.random.rand(1000, 10)
arr2 = np.random.rand(2000, 20)
arr3 = np.random.rand(10, 10000)
np.savez("many_arrs", arr1, arr2, arr3)
!ls -lh
loading files
arrs = np.load("many_arrs.npz")
arrs.files
arrs['arr_1'].shape
np.savez_compressed("many_arrs_compressed", arr1, arr2, arr3)
!ls -lh
npZeros = np.zeros((10000, 10000))
np.savez_compressed("npZeros_compressed", npZeros)
np.savez("npZeros", npZeros)
ls - lh
!ls -lh