printed NONE while using np.fill_diagona for matrix while filling digonal with 0?

Issue

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.

Solution

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.

Answered By – Warren Weckesser

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published