一对一排阵列和解析到功能
我想分别将行中的一个数量(10,4)归功于一个阵列(10,4),并分析列的每个元素,分别为给定的函数变量(x1,x2,x3,x4)。我应该如何设置循环,以便一个循环可以迭代行(一个一个循环),而第二个循环可以将列的值分配给函数变量?变量也可能需要在相应的功能之前定义。非常感谢! 这是我的代码:
import pandas as pd
import numpy as np
nv = 4
lb = [0, 0, 0, 0]
ub = [20, 17, 17, 15]
n = 10
def random_population(nv,n,lb,ub):
pop = np.zeros((n, nv))
for i in range(n):
pop[i,:] = np.random.uniform(lb,ub)
return pop
population = random_population(nv, n, lb, ub)
def test(x1, x2, x3, x4):
##Assignment statement
y = (10*x1 + 45.5*x2 - 6*x3) * x4
return y
I want to iterate rows one by one of an array of population (10,4) and parse each element of a column to given variables of function (x1, x2, x3, x4), respectively. How should I set loops so that one loop can iterate rows (one by one) and the second loop can assign values of columns to the function's variables? The variables also may need to define before function accordingly. Many thanks in advance!
Here is my code:
import pandas as pd
import numpy as np
nv = 4
lb = [0, 0, 0, 0]
ub = [20, 17, 17, 15]
n = 10
def random_population(nv,n,lb,ub):
pop = np.zeros((n, nv))
for i in range(n):
pop[i,:] = np.random.uniform(lb,ub)
return pop
population = random_population(nv, n, lb, ub)
def test(x1, x2, x3, x4):
##Assignment statement
y = (10*x1 + 45.5*x2 - 6*x3) * x4
return y
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论