Random Numbers in NumPy
Machine Learning courses with 100+ Real-time projects Start Now!!
Program 1
from numpy import random
#Random number
#randint() , rand()
# How to generate Random Array
# How to generate Random number from array using choice()
x=random.choice([10,4,6,1,5,8,7,12,10],size=(2,2))
print(x)
# myar2=random.randint(1000,size=(2,3,4))
# print(myar2)
# x=random.randint(100)
# print(x)
# x=random.rand(5)
# print(x)
# toss=random.randint(2)
# if(toss==0):
# print("first Player won")
# else:
# print("second player won")
# myar1=random.randint(100,size=5)
# print(myar1)
# Difference between copy and view
# ar1=np.array([48,13,27,330,448,50,77,88,399,12])
# ar2=ar1.copy()
# ar3=ar1.view()
# print("copy: ",ar2.base)
# print("View:",ar3.base)
# Rules of Arithmetic operations in numpy array
# 1. Shape of Arrays must be same
# 2. Second Array must have atleast one dimension and
# the number of element should be same as first array
# 3. Second array having one element
#
# ar1=np.array([[1,2,3],[4,5,6]])
# ar2=np.array([[1,2,3],[4,5,6],[7,8,9]])
# print(ar1)
# print("\n\n")
# print(ar2)
# print("\n\n")
# ar3=np.power(ar1,2)
# print(ar3)
Did you like this article? If Yes, please give DataFlair 5 Stars on Google

