numpy - 通过重复的函数调用将数组附加到自身
问题描述
我试图通过重复调用一个函数来附加一个数组。当我将追加命令放在循环中时,这可以正常工作,但当循环调用应该执行追加的函数时则不行。
import numpy as np
test_value = 555
i = 0
j = 0
test_array = np.empty([0, 3])
def test(test_value, i, j, test_array):
test_temp = []
test_temp.append(i)
test_temp.append(j)
test_temp.append(test_value)
test_temp_1 = test_temp
test_temp_2 = np.array(test_temp_1)
test_temp_2 = np.reshape(test_temp_2, (1,3))
test_array = np.append(test_array, test_temp_2, axis=0)
return test_array
for i in range(0,10):
i = i + 1
j = j + 2
test(test_value, i, j, test_array)
print ("test array", test_array)
理想情况下,test_array 每次循环时都会添加一个新行,但是 test_array 的最终打印保持为空。
干杯
解决方案
推荐阅读
- python - 如果函数在不应该执行时执行
- c# - 在访问者模式中的节点之间传递数据
- javascript - 在我的代码中,mousemove 属性不起作用并更改了输入类型范围。能解释一下为什么吗?
- python - 使用 python 中的命令打开多个 selenium webdrivers(任务)
- python - VSCode忽略断点
- django - 如何通过模板从数据库中删除记录?
- python - 使用 selenium.webdriver 登录后,如何识别包含指向我的 linkedin 配置文件的链接的元素?
- azure - Azure OAuth:无法在管理员同意的情况下以编程方式创建应用以获得权限
- c# - 从不同类型的列表中搜索名称
- yii2 - Yii2模型规则黑名单词数组检查