T
T
Timebird2016-07-17 10:49:01
Python
Timebird, 2016-07-17 10:49:01

How to pull the first element from a numpy.matrix?

Hello!
There is a matrix np.matrix, for example, of the form:

M = np.matrix()

It is necessary to pull out the element [0][0] from here, that is, one. I tried like this:
for i in M:
    coeff_a_from_M = i[0][0]
print('coeff_a_from_M: ', coeff_a_from_M)

For some reason, in this case, it prints out:
coeff_a_from_A:
What is the error in my code and how to write it correctly in this case?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AtomKrieg, 2016-07-17
@Timebird

import numpy as np
M = np.matrix()
print(M[0,0])

Code error - analyze for yourself:
for idx, el in enumerate(M):
    coeff_a_from_M = el[0][0]
    print(idx, '-->', el, '-->', el[0], '-->', coeff_a_from_M)

P
protven, 2016-07-17
@protven

import numpy as np
M = np.matrix()

print M.item(0,0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question