Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy.io import mmread
- import math,sys
- def trace(arr):
- out = 0
- rows = len(arr)
- cols = len(arr[0])
- for i in range(rows):
- out += arr[i][i]
- return out
- def frobenious(arr):
- out = 0
- rows = len(arr)
- cols = len(arr[0])
- for i in range(rows):
- for j in range(cols):
- out += arr[i][j]*arr[i][j]
- return math.sqrt(out)
- def diagdom(arr):
- out = True
- rows = len(arr)
- cols = len(arr[0])
- for i in range(rows):
- for j in range(cols):
- if(arr[i][j] > arr[i][i]):
- out = False
- return out
- def symmetric(arr):
- out = True
- rows = len(arr)
- cols = len(arr[0])
- for i in range(rows):
- for j in range(cols):
- if(arr[i][j] != arr[j][i]):
- out = False
- return out
- def nnz(arr):
- out = 0
- rows = len(arr)
- cols = len(arr[0])
- for i in range(rows):
- for j in range(cols):
- if(arr[i][j] != 0):
- out += 1
- return out
- if __name__ == '__main__':
- try:
- print(sys.argv[1])
- a = mmread(sys.argv[1])
- b = a.toarray()
- print("Enter 1 for trace, 2 for frobenious, 3 for diagonal dominant, 4 for symmetric and 5 for number of non-zero")
- inp = int(input())
- # print(inp)
- if(inp==1):
- print(trace(b))
- elif(inp==2):
- print(frobenious(b))
- elif(inp==3):
- print(diagdom(b))
- elif(inp==4):
- print(symmetric(b))
- elif(inp==5):
- print(nnz(b))
- else:
- print("Enter correct code")
- except:
- print("Enter in right format: python3 features.py matrix-market-filename")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement