gpt4 book ai didi

python - 从其他 numpy 数组创建 numpy 数组

转载 作者:太空宇宙 更新时间:2023-11-03 18:26:58 26 4
gpt4 key购买 nike

我有这个数组:

data = [[  1.00000000e-01   1.00000000e-03]
[ 2.00000000e-01 2.00000000e-03]
[ 3.00000000e-01 3.00000000e-03]
[ 4.00000000e-01 4.00000000e-03]
[ 5.00000000e-01 5.00000000e-03]
[ 6.00000000e-01 6.00000000e-03]
[ 7.00000000e-01 7.00000000e-03]
[ 8.00000000e-01 8.00000000e-03]
[ 9.00000000e-01 9.00000000e-03]
[ 1.00000000e+00 1.00000000e-02]
[ 1.10000000e+00 1.10000000e-02]
[ 1.20000000e+00 1.20000000e-02]
[ 1.30000000e+00 1.30000000e-02]
[ 1.40000000e+00 5.23359560e-02]
[ 1.50000000e+00 1.04528463e-01]
[ 1.60000000e+00 1.56434465e-01]
[ 1.70000000e+00 2.07911691e-01]
[ 1.80000000e+00 2.58819045e-01]
[ 1.90000000e+00 3.09016994e-01]
[ 2.00000000e+00 3.58367950e-01]
[ 2.10000000e+00 4.06736643e-01]
[ 2.20000000e+00 4.53990500e-01]
[ 2.30000000e+00 5.00000000e-01]
[ 2.40000000e+00 5.44639035e-01]
[ 2.50000000e+00 5.87785252e-01]
[ 2.60000000e+00 6.29320391e-01]
[ 2.70000000e+00 6.69130606e-01]
[ 2.80000000e+00 7.07106781e-01]
[ 2.90000000e+00 7.43144825e-01]
[ 3.00000000e+00 7.77145961e-01]
[ 3.10000000e+00 8.09016994e-01]
[ 3.20000000e+00 8.38670568e-01]
[ 3.30000000e+00 8.66025404e-01]
[ 3.40000000e+00 8.91006524e-01]
[ 3.50000000e+00 9.13545458e-01]
[ 3.60000000e+00 9.33580426e-01]
[ 3.70000000e+00 9.51056516e-01]
[ 3.80000000e+00 9.65925826e-01]
[ 3.90000000e+00 9.78147601e-01]
[ 4.00000000e+00 9.87688341e-01]
[ 4.10000000e+00 9.94521895e-01]
[ 4.20000000e+00 9.98629535e-01]
[ 4.30000000e+00 1.00000000e+00]
[ 4.40000000e+00 1.00100000e+00]
[ 4.50000000e+00 1.00200000e+00]
[ 4.60000000e+00 1.00300000e+00]
[ 4.70000000e+00 1.00400000e+00]
[ 4.80000000e+00 1.00500000e+00]
[ 4.90000000e+00 1.00600000e+00]
[ 5.00000000e+00 1.00700000e+00]]

我需要从中创建第二个数组,该数组由每行的第一个值组成:

rows = [[1.00000000e-01], [2.00000000e-01], ...., [5.00000000e+00]]

有没有一种方法可以做到这一点?谢谢

最佳答案

设置示例数组:

In [17]: a = np.arange(10).reshape(5,2)

In [18]: a
Out[18]:
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])

然后根据每行中第一个值产生的数组的形状:

In [19]: a[:,0]
Out[19]: array([0, 2, 4, 6, 8])

In [20]: a[:,0][:,None] # or a[:,0,None] or a[:,0,np.newaxis]
Out[20]:
array([[0],
[2],
[4],
[6],
[8]])

关于python - 从其他 numpy 数组创建 numpy 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22996972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com