-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMidterm Activity-2
More file actions
55 lines (52 loc) · 1.66 KB
/
Midterm Activity-2
File metadata and controls
55 lines (52 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'''
Activity-2
'''
import numpy as np
import random
class BigMatrixMath:
empty_list=[]
new_list=[]
#generating a random matrix with given set of numbers and a defined size of matrix
def addMatrix(empty_list):
global myArray
myArray=np.array=([])
myArray=np.arange(-70,160,1)
# myArray=np.random.randint(-70,160, (40,40))
#myArray=np.linspace(-70,160,90)
# print(type(myArray))
print(myArray)
empty_list=empty_list.append(myArray)
addMatrix(empty_list)
#printing the dimensions and shape of the array
def printDimension(myArray):
print("-----------------------")
print("The dimension of the array is: ", myArray.ndim)
print("-----------------------")
print("The shape of the array is: ", myArray.shape)
printDimension(myArray)
#creating a random matrix with user desired rows and columns
def addMatrix2():
r= int(input("How many rows: "))
c=int(input("How many columns: "))
global myArray2
myArray2= np.ones((r,c))
print(myArray2)
addMatrix2()
#calculating the dot product and assigning some exceptions
def dotProductElgible(myArray,myArray2):
try:
print(myArray.dot(myArray2))
except ValueError:
print("Its not an appropiate matrix size for multiplication")
print("Make sure that the number of rows in 1st matrix the number of columns in the second one")
dotProductElgible(myArray,myArray2)
import numpy as np
add1=np.array([[1,2],[3,4]])
add2=np.array([[5,6],[7,8]])
#combining two different array
add1.append(add2)
#reformating a set of numbers in user defined form
def reformating():
formatarray=np.arange(12).reshape((3,4))
print(formatarray)
reformating()