【发布时间】:2021-07-22 07:07:21
【问题描述】:
我正在尝试将 2 个随机生成的列表合并为一个,但它会明智地添加它们。假设我生成了 2 个列表,每个列表有 2 个随机数,我希望我的输出列表是数字。例如:
import numpy as np
x1 = np.random.uniform(0,0.1, 2)
x2 = np.random.uniform(0,0.1, 2)
x = x1 + x2
print(x1)
print(x2)
print(x)
The output is:
[0.06878713 0.03807816]
[0.01801809 0.06292975]
[0.08680523 0.10100791]
But I want my output as
[0.06878713 0.03807816]
[0.01801809 0.06292975]
[0.06878713 0.03807816 0.01801809 0.06292975]
如果我使用 append() 或 extend() 它给了我:AttributeError: 'numpy.ndarray' object has no attribute 'append'。
【问题讨论】:
-
问题是你认为它们是列表,但它们是 numpy 数组。
标签: python-3.x list numpy random