Lee
Lee

Reputation: 31040

Get a value from a numpy matrix

If I have a numpy matrix:

>>> S
matrix([[ 0.66581073+0.00033919j],
        [ 0.81568896-0.03291265j],
        [ 0.99884785+0.00045446j]])

How do I get an element, without the matrix wrapper?

If I try:

>>> S[0]

I get:

matrix([[ 0.66581073+0.00033919j]])   

whereas what I want is:

0.66581073+0.00033919j

I have had a look at the documentation and can't find a function/operator to do this.

Upvotes: 1

Views: 4455

Answers (1)

jamylak
jamylak

Reputation: 133514

>>> import numpy as np
>>> I = np.matrix([[ 0.66581073+0.00033919j],
        [ 0.81568896-0.03291265j],
        [ 0.99884785+0.00045446j]])
>>> 
>>> I[0, 0]
(0.66581073000000002+0.00033919000000000001j)

Upvotes: 2

Related Questions