三行代码  ›  专栏  ›  技术社区  ›  user19657580

在Python中打印两个numpy数组的列表

  •  -1
  • user19657580  · 技术社区  · 1 月前

    Path 它应该由两个numpy数组的列表组成,但它只打印最后一个数组。我给出了电流和预期输出。

    import numpy as np
    
    Ii01 = [np.array([[0, 2],
            [0, 3],
            [0, 4],
            [1, 5],
            [2, 3],
            [2, 4],
            [3, 1],
            [3, 5],
            [4, 3],
            [4, 6],
            [5, 6],
            [5, 7],
            [5, 8],
            [6, 7],
            [6, 8],
            [7, 8]]),
     np.array([[0, 2],
            [0, 3],
            [0, 4],
            [1, 5],
            [2, 3],
            [2, 4],
            [3, 1],
            [3, 5],
            [4, 3],
            [4, 6],
            [4, 7],
            [5, 8],
            [5, 9],
            [6, 7],
            [7, 5],
            [7, 8],
            [7, 9],
            [8, 9]])]
    
    Iv01 = [np.array([[0.5928417218382795  ],
            [1.0598523225018839  ],
            [1.0038922911359835  ],
            [0.5228083275600917  ],
            [0.45152663276269006 ],
            [0.33163464481335625 ],
            [0.6382821834929433  ],
            [1.1929711967814043  ],
            [0.151430568179323   ],
            [1.2882852997187433  ],
            [0.020634234459323438],
            [0.3371248675176444  ],
            [1.0339712303899318  ],
            [0.3170028087537722  ],
            [1.0107667057670484  ],
            [0.645202745957077   ]]),
     np.array([[0.6413512609273813 ],
            [1.101096390751953  ],
            [1.1271899958869345 ],
            [0.5129288710922218 ],
            [0.44299417932362256],
            [0.39992456692863954],
            [0.6262206291648664 ],
            [1.1704277398685619 ],
            [0.0811025900626848 ],
            [0.4804819688823268 ],
            [1.1198920618079702 ],
            [0.33075425274871   ],
            [1.0794187146885863 ],
            [0.5875522376738217 ],
            [0.05687040105172758],
            [0.3822797557154033 ],
            [1.1388373266868645 ],
            [0.6979967492676955 ]])]
    
    for i in range(0,len(Ii01)):
            uniq = np.unique(Ii01[i][:, 1][None, :])
            y =Iv01[i][:, 0]
            x = Ii01[i][:, 1][:, None] == uniq
            output = np.vstack((np.linalg.lstsq(x, y, rcond=None)[0], uniq)).T
            Path=output[:,0]
            Path = np.insert(Path, 0, 10)   #fixed inlet
    print([Path])        
    

    电流输出为

    [array([10.                 ,  0.6262206291648664 ,  0.6413512609273813 ,
            0.5417310533794202 ,  0.763557281407787  ,  0.580075670670837  ,
            0.48048196888232686,  0.8537221497408958 ,  0.35651700423205657,
            0.9720842635477158 ])]
    

    [array([10.                 ,  0.6382821834929432 ,  0.5928417218382795 ,
            0.5542698411479658 ,  0.6677634679746701 ,  0.8578897621707481 ,
            0.6544597670890333 ,  0.32706383813570833,  0.8966468940380192 ]),
    array([10.                 ,  0.6262206291648664 ,  0.6413512609273813 ,
            0.5417310533794202 ,  0.763557281407787  ,  0.580075670670837  ,
            0.48048196888232686,  0.8537221497408958 ,  0.35651700423205657,
            0.9720842635477158 ])]
    
    1 回复  |  直到 1 月前
        1
  •  1
  •   mauro    1 月前

    那是因为你总是覆盖 Path

    Path = []
    for i in range(0, len(Ii01)):
        uniq = np.unique(Ii01[i][:, 1][None, :])
        y = Iv01[i][:, 0]
        x = Ii01[i][:, 1][:, None] == uniq
        output = np.vstack((np.linalg.lstsq(x, y, rcond=None)[0], uniq)).T
        Path.append(np.insert(output[:, 0], 0, 10))  # fixed inlet
    print(Path)