In [4]:
# Day 1 - Q. Import numpy as `np` and print the version number.
import numpy as np
print( 'Version: ',np.version.version, np.version)
In [21]:
# Day 2 - Q. Create a 1D array of numbers from 0 to 9
# Output - array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
# There are 5 ways to create an array in NumPy 1) From a list\tuple 2) creation object 3) Reading from disk 4) raw byes in strings\buffers 5) Special Library
# ones, zeros, random.random, empty, full, arange, linspace
fromList = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
print("From a list : ", fromList)
fromZero = np.zeros(10, dtype = np.integer)
for i,x in enumerate(fromZero):
fromZero[i] = i
print("From zeros : ", fromZero)
from io import StringIO
c = StringIO("0, 1, 2, 3, 4, 5, 6, 7, 8, 9")
fromIO = np.loadtxt(c, delimiter=',', dtype=np.int64)
print("From IO : ", fromIO)
In [2]:
print(raw)