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?
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?
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.
>>> 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.