tags:

views:

162

answers:

3

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?

A: 

Doesn't

matrix[x][y]

work?

adamse
+1  A: 

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.

danben
that was very useful,tnx again.....
Alex
Glad it helped. Standard practice on SO is to accept the most helpful answer to a question by clicking the check mark underneath the answer's score. SO keeps track of users' accept rate, and users with low accept rates will have a harder time getting their questions answered.
danben
A: 
>>> 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.

cppb