Introduction to NumPy
Practical
import numpy as np
import random
Q1. To creating array from list
marks = [Link]([50, 60, 85])
print('creating array from list')
print(marks)
Q2. To create an array with values ranging from 10 to 100
a=[Link](10,100,10)
print('creating array with values ranging from 10 to 100')
print(a)
Q3. To create an array with 5 random floating numbers between 0 and 1
b=[Link](5)
print('creating array with 5 random floating numbers between 0 and 1')
print(b)
Q4. To create an array with 5 random integer numbers less than 20
c=[Link](20,size=5)
print('creating array with 5 random integer numbers between less than 20')
print(c)
Q5. To create an two-dimensional array with 2 x 3 random integer numbers less than 20
d=[Link](20,size=(2,3))
print('creating array two-dimensional array with 2 x 3 numbers between less than 20')
print(d)
Q6. To create a two-dimensional array with all values as 1
e=[Link]((2,3))
print('creating array two-dimensional array with 2 x 3 with all values as 1')
print(e)
Q7. To create a two-dimensional array with all values as 5
e=[Link]((2,3),5)
print('creating array two-dimensional array with 2 x 3 with all values as 5')
print(e)
Q8. To store 5 random numbers in 2 numpy array and perform all arithmetical operations
import numpy as np
import random
array_one = [Link](20,size=5)
array_two = [Link](20,size=5)
sum_array = array_one + array_two #adding 2 array elements
diff_array = array_one - array_two #subtracting 2 array elements
prod_array = array_one * array_two #product of 2 array elements
div_array = array_one / array_two #dividing 2 array elements
exp_array = array_one ^ 2 #raising the content of array_one with 2
flr_array = array_one // array_two #floor dividing 2 array elements
mod_array = array_one % array_two #remainder after dividing 2 array elements
#output
print("Content of array 1",array_one)
print("Content of array 2",array_two)
print("array sum",sum_array)
print("array difference",diff_array)
print("array product",prod_array)
print("array division",div_array)
print("array exponent by 2",exp_array)
print("array floor division",flr_array)
print("array remainder",mod_array)