In [1]:
import numpy
In [2]:
l1 = [1,2,3]
arr1 = numpy.array(l1)
arr1
Out[2]:
In [3]:
type(arr1)
Out[3]:
In [4]:
l2d = [[1,2,3],[4,5,6]]
arr2d = numpy.array(l2d)
arr2d
Out[4]:
In [5]:
type(arr2d)
Out[5]:
In [6]:
l3d = [[[1,2],[3,4]], [[1,2],[3,4]]]
arr3d = numpy.array(l3d)
arr3d
Out[6]:
In [7]:
numpy.ones(shape=(4,4)) #pass shapre as a tuple
Out[7]:
In [8]:
numpy.zeros(shape = (2,2))
Out[8]:
In [11]:
numpy.eye(3)
Out[11]:
In [12]:
numpy.arange(start=0, stop=10, step=1) #stop is non inclusive
Out[12]:
In [13]:
numpy.arange(21) #the stop arg is the only compulsory arg
Out[13]:
linspace is similar, returns contiguous numbers in linearly spaced intervals. These numbers conform to uniform distribution
In [15]:
numpy.linspace(start=3, stop=21, num=7) #return 7 numbers between 3 and 21 (inclusive)
Out[15]:
In [16]:
numpy.random.rand(3,3) #specify shape in individual arguments
Out[16]:
In [17]:
numpy.random.rand(3,3,3)
Out[17]:
In [19]:
numpy.random.randint(low=30, high=200, size=10)
Out[19]:
In [20]:
arr2 = numpy.random.rand(3,3,3)
arr2.shape
Out[20]:
In [21]:
arr3 = numpy.random.randint(low=30, high=200, size=10)
arr3.shape
Out[21]:
thus shape is returned as a tuple.
In [22]:
arr2.dtype
Out[22]:
In [23]:
arr3.dtype
Out[23]:
In [25]:
arr2
Out[25]:
In [24]:
arr2.max() #max element in the entire 3d array
Out[24]:
In [26]:
arr2.max(axis=1) #max in each column
Out[26]:
In [32]:
arr2.max(axis=2) #max in each row
Out[32]:
min method to find the minimum
In [34]:
arr2.min()
Out[34]:
In [35]:
arr2.min(axis=1)
Out[35]:
In [36]:
arr2.argmax() #location max element in the 3D array
Out[36]:
In [38]:
arr2.argmax(1) #indices of each max element
Out[38]:
In [39]:
arr2.argmin(1)
Out[39]:
In [41]:
arr3
Out[41]:
In [42]:
arr3.shape
Out[42]:
In [43]:
arr3.reshape((5,2))
Out[43]: