-4
n = int(input("Enter the number of rows in a matrix: "))
#key matrix for Hill Cipher
key = [[0] * n for i in range(n)]
#print(key)

def key_mat(key):
    # To fill the elements in the matrix "key"
    for i in range(n):
        for j in range(n):
            key[i][j] = int(input())

    #print(np.array(key))
    key = np.array(key)
    print("Key = ",key)
    return key
key_mat(n,key)

# "adjoint of a matrix" in numpy is obtained by np.matrix.getH()
#getH means get Hermitian transpose.
adj_Key = key.getH()
print(adj_Key)

And I got error at this line adj_Key = key.getH()

AttributeError: 'list' object has no attribute 'getH'

I want to find adjoint of the matrix "key", and doing so I am getting this error..How to resolve it.

Thanks

Lubna Khan
  • 91
  • 1
  • 8
  • That line isn't even in the code you've posted. – Daniel Roseman Sep 24 '18 at 19:29
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. – Prune Sep 24 '18 at 19:33
  • key_mat returns an array, but doesn''t set key in the gloabal environment. key is still the initial list. – hpaulj Sep 24 '18 at 23:10

1 Answers1

0

key is a list, not a matrix. You need to convert it to a matrix before calling getH

>>> n = 5
>>> key = [[0] * n for i in range(n)]
>>> type(key)
<class 'list'>
>>> np.matrix(key).getH()
matrix([[0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0]])
c2huc2hu
  • 2,447
  • 17
  • 26