/ Python And R Data science skills: 32 reshape and rand ind methods
Showing posts with label 32 reshape and rand ind methods. Show all posts
Showing posts with label 32 reshape and rand ind methods. Show all posts

Sunday, 4 February 2018

32 reshape and rand ind methods in python

32 DS Python Numpy
In [5]:
import numpy as np
In [ ]:
# np.random.randint(1,100)
In [6]:
np.random.randint(1,100)
Out[6]:
25
In [7]:
z=np.random.randint(1,100)
In [8]:
z
Out[8]:
55
In [12]:
 
Out[12]:
41
In [4]:
randint(1,20)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-b634dbb6741c> in <module>()
----> 1 randint(1,20)

NameError: name 'randint' is not defined
In [17]:
from numpy.random import randint
In [18]:
randint(1,20)
Out[18]:
12
In [21]:
from numpy.random import randint
In [31]:
randint(2,3)
Out[31]:
2
In [34]:
randint(1,20,4)
Out[34]:
array([4, 2, 9, 1])
In [37]:
za=np.arange(25)
In [38]:
za
Out[38]:
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19, 20, 21, 22, 23, 24])
In [45]:
za.reshape(5,5,order='F')
Out[45]:
array([[ 0,  5, 10, 15, 20],
       [ 1,  6, 11, 16, 21],
       [ 2,  7, 12, 17, 22],
       [ 3,  8, 13, 18, 23],
       [ 4,  9, 14, 19, 24]])