0

When load matrices from mat file in python using scipy.io, it makes dictionary where key is name of matrix,and value is 2D array of that matrix.

How can i access elements in this array?

3 Answers 3

2

Suppose you have

mat = sio.loadmat('a.mat')

Then you can see which matrices were loaded by

print mat

For each key key in the dictionary, you can retrieve the corresponding matrix by

my_matrix = mat[key]

my_matrix is a 2d array representing the matrix. So to get row 0 of the matrix, you would use my_matrix[0], and to get element(0,0) of the matrix, you would use my_matrix[0][0].

Here's a nice tutorial you can use for other basic functionality.

Sign up to request clarification or add additional context in comments.

Comments

0

Doesn't

matrix[x][y]

work?

Comments

0
>>> A = array([ [1,2], [3,4], [5,6]])
>>> A
array([[1, 2],
       [3, 4],
       [5, 6]])
>>> A[0]
array([1, 2])
>>> A[0][0]
1

Here A can be a value in the dict object you have created.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.