Numpy, is transposition a representation and doesn't make the matrix symmetrical?

reading a scipy lecture: http://scipy-lectures.imtqy.com/intro/numpy/operations.html

there is an example:

>>> a = np.triu(np.ones((3, 3)), 1)
>>> a
array([[ 0.,  1.,  1.],
       [ 0.,  0.,  1.],
       [ 0.,  0.,  0.]])
>>> a.T
array([[ 0.,  0.,  0.],
       [ 1.,  0.,  0.],
       [ 1.,  1.,  0.]])

and then he says: enter image description here

and I don’t understand why. I conducted an experiment, and this makes it symmetrical. enter image description here


EDIT 1:

The same results are valid for a random matrix: enter image description here

+4
source share
1 answer

I think I understand what the purpose of the warning is, although I do not know enough about Numpy's internal functions to find out why the problem does not occur.

, , , ( ). Numpy , .

() - += 2d-:

def matrix_iadd(lhs, rhs):
    for i in range(lhs.shape[0]):
        for j in range(lhs.shape[1]):
            lhs[i,j] += rhs[i,j]
    return lhs

, , rhs - , lhs (, ). :

>>> a = np.arange(9)
>>> a.shape=(3,3)
>>> a
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
>>> a.T
array([[0, 3, 6],
       [1, 4, 7],
       [2, 5, 8]])
>>> matrix_iadd(a, a.T)
array([[ 0,  4,  8],
       [ 7,  8, 12],
       [14, 19, 16]])

, , , , . lhs[0,1] ( rhs[0,1] 3 1), rhs[1,0] . , lhs[1,0] , rhs[1,0] .

, , , , numpy . , Numpy, , , , Numpy. . , , , .

+5

Source: https://habr.com/ru/post/1543870/


All Articles