如何更改矩阵的符号?

时间:2019-02-20 04:27:32

标签: python

我正在编辑一个程序,该程序给了我一个稀疏矩阵

具有这种表示法的矩阵

Y =   

  (0, 0)        -17.3611111111j
  (3, 0)        17.3611111111j
  (7, 1)        16j
  (1, 1)        -16j
  (2, 2)        -17.0648464164j
  (5, 2)        17.0648464164j
  (8, 3)        (-1.36518771331+11.6040955631j)
  (3, 3)        (3.30737896203-39.3088887261j)
  (0, 3)        17.3611111111j
  (4, 3)        (-1.94219124871+10.5106820519j)
  (4, 4)        (3.22420038714-15.8409270142j)
  (3, 4)        (-1.94219124871+10.5106820519j)
  (5, 4)        (-1.28200913842+5.58824496236j)
  (5, 5)        (2.43709661931-32.1538618051j)
  (2, 5)        17.0648464164j
  (4, 5)        (-1.28200913842+5.58824496236j)
  (6, 5)        (-1.15508748089+9.78427042636j)
  (6, 6)        (2.77220995414-23.3032490233j)
  (5, 6)        (-1.15508748089+9.78427042636j)
  (7, 6)        (-1.61712247325+13.6979785969j)
  (7, 7)        (2.80472685254-35.4456131302j)
  (6, 7)        (-1.61712247325+13.6979785969j)
  (8, 7)        (-1.18760437929+5.97513453331j)
  (1, 7)        16j
  (8, 8)        (2.5527920926-17.3382300964j)
  (7, 8)        (-1.18760437929+5.97513453331j)
  (3, 8)        (-1.36518771331+11.6040955631j)

我想以正常方式获取矩阵

x =      np.array ([[-17.3611111111j,   0,  0,  17.3611111111j, 0,  0,  0,  0,  0],
                    [0, -16j,      0,     0,    0,  0,  0,  16j,    0],
                    [0, 0,     -17.0648464164j,   0,    0,  17.0648464164j, 0,  0,  0],
                    [17.3611111111j,    0,  0,  (3.30737896203-39.3088887261j),     (-1.94219124871+10.5106820519j),       0,      0,      0,      (-1.36518771331+11.6040955631j)],
                    [0, 0,  0,  (-1.94219124871+10.5106820519j),  (3.22420038714-15.8409270142j),   (-1.28200913842+5.58824496236j),    0,     0,       0],
                    [0, 0,  17.0648464164j, 0,      (-1.28200913842+5.58824496236j),       (2.43709661931-32.1538618051j),     (-1.15508748089+9.78427042636j),   0,       0    ],
                    [0, 0,  0,  0,      0   ,   (-1.15508748089+9.78427042636j),       (2.77220995414-23.3032490233j),    (-1.61712247325+13.6979785969j),    0 ],
                    [0, 16j,    0,  0,  0,  0,  (-1.61712247325+13.6979785969j),    (2.80472685254-35.4456131302j),   (-1.18760437929+5.97513453331j)],
                    [0, 0,     0,     (-1.36518771331+11.6040955631j),    0,       0,   0,  (-1.18760437929+5.97513453331j),    (2.5527920926-17.3382300964j)]]) 

如何将第一个矩阵转换为第二个矩阵?

1 个答案:

答案 0 :(得分:0)

我猜您想从help(scipy.sparse)转换稀疏矩阵的格式:

   bsr_matrix - Block Sparse Row matrix
   coo_matrix - A sparse matrix in COOrdinate format
   csc_matrix - Compressed Sparse Column matrix
   csr_matrix - Compressed Sparse Row matrix
   dia_matrix - Sparse matrix with DIAgonal storage
   dok_matrix - Dictionary Of Keys based sparse matrix
   lil_matrix - Row-based linked list sparse matrix

在这种情况下,您只需要将其转换为数组即可:

x = Y.toarray()