Home > database >  Storing value in a separate matrix using Python
Storing value in a separate matrix using Python

Time:03-02

How do I store value in a new matrix, T1 with the given criterion? All the outputs are attached.

import numpy as np

P1 = np.array([[0.04, 0.55, 0.16, 0.39, 0.51],
       [0.23, 0.85, 0.73, 0.53, 0.11],
       [0.43, 0.26, 0.1 , 0.06, 0.88],
       [0.95, 0.27, 0.61, 0.  , 0.17],
       [0.01, 0.72, 0.87, 0.14, 0.06]])

P2=0.1

T=P1[0,:]
T1=P2>T
print(T1)

Current output:

[ True False False False False]

Desired output:

T1=array([[0.04]])

CodePudding user response:

You just need to change this:

T1=P2>T
print(T1)

To this:

T1=T[P2>T]
print(T1)

Note that, this results in printing the following:

[0.04]

If you are interested in having a matrix, try changing the print(T1) to print([T1])

  • Related