Home > Back-end >  printed NONE while using np.fill_diagona for matrix while filling digonal with 0?
printed NONE while using np.fill_diagona for matrix while filling digonal with 0?

Time:06-11

I was trying to np.fill_dagonl(x,0) in the below matrix

array([[1.        , 1.        , 1.        , ..., 1.        , 1.        ,
    1.        ],
   [1.        , 1.        , 1.        , ..., 1.        , 0.98344802,
    1.        ],
   [1.        , 1.        , 1.        , ..., 1.        , 1.        ,
    1.        ],
   ...,
   [1.        , 1.        , 1.        , ..., 1.        , 1.        ,
    1.        ],
   [1.        , 0.98344802, 1.        , ..., 1.        , 1.        ,
    1.        ],
   [1.        , 1.        , 1.        , ..., 1.        , 1.        ,
    1.        ]])

When I print it shows none. Someone tell me why and how to correct it.

The matrix size is 1862*1862.

CodePudding user response:

fill_diagonal operates on its argument in place, and returns None.

I suspect you did something like

x = np.fill_diagonal(x, 0)

which set x to None, because that is what fill_diagonal returned. Change that to

np.fill_diagonal(x, 0)

Then when you print x, you'll see that is has been changed.

  • Related