Assignment On Numpy (2) : #Question 1
Assignment On Numpy (2) : #Question 1
[ ]: NAME=RAHUL RAMESH
RATHOD MIS=112110115
BATCH=F
BRANCE=MECHANICAL
↪elements respectively.
import numpy as np
array_zeros=np.zeros(5)
array_ones=np.ones(10)
array=np.linspace(0,50,10)
print("The array of zeros:")
print(array_zeros)
print("The array of ones:")
print(array_ones)
print("An array of 10 Elements between 0 to 50:")
print(array)
#s=np.arange(0,50,50/9)
#print(s)
1
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48]
2
Maximum Grade: 10
Minimum Grade: 3
Random Array:
[[0.6725206 0.97172572 0.54975316 0.75395661]
[0.29987882 0.06957545 0.91819967 0.55450947]
[0.8606592 0.26261473 0.27814343 0.63766782]
[0.94737535 0.06362616 0.34960625 0.70174297]]
Array 1: [2 3 4 5]
Array 2: [3 2 1 0]
Result (Array 1 ** Array 2): [8 9 4 1]
[22]: #Question 7. Generate an array which actual and obtained values for
10␣ ↪performance parameters of machines. The machine is ideal if the
actual␣ ↪values are multiple of obtained values. Check if the machine is
ideal.
import numpy as np
actual_values = np.random.randint(1, 20, 10)
obtained_values = np.random.randint(1, 20, 10)
ideal_machine = np.all(actual_values % obtained_values == 0)
print("Actual Values:", actual_values)
print("Obtained Values:", obtained_values)
if ideal_machine:
print("\nThe machine is ideal.")
else:
print("\nThe machine is not ideal.")
Original Array:
[[1 2 3 4 5]
[ 678910]
[11 12 13 14 15]
[16 17 18 19 20]
[21 22 23 24 25]]
4
[1]: #Question 10. Create a vector of size 10 with values ranging from 0 to␣
import numpy as np
1, with both end values 0 and 1 excluded. Hint: Linspace
↪
A = np.random.rand(5, 5)
B = np.random.rand(5, 5)
result = np.dot(A, B)
diagonal_elements = np.diagonal(result)
print("Matrix A:")
print(A)
print("\nMatrix B:")
print(B)
print("\nDot Product of A and B:")
print(result)
print("\nDiagonal Elements of the Dot Product:")
print(diagonal_elements)
Matrix A:
[[0.48685434 0.45925953 0.6169875 0.73368454 0.06589155]
[0.4886029 0.91513282 0.85327392 0.49421867 0.9937429 ]
[0.46338284 0.60996615 0.14995036 0.33224589 0.42612583]
[0.06254882 0.0685735 0.97291803 0.90810684 0.34065169]
[0.18868624 0.95289157 0.15167439 0.14840683 0.86418335]]
Matrix B:
[[0.44984817 0.0970476 0.62450248 0.47225828 0.66031112]
[0.36171573 0.73416862 0.23434909 0.03672095 0.26904383]
[0.94981339 0.31521542 0.68436479 0.51810546 0.28239686]
[0.95504321 0.90357278 0.81522721 0.37653887 0.38126006]
[0.67858842 0.20425422 0.00321858 0.2679855 0.77713093]]