I'm a beginner in python. I wrote a function as follows:
import numpy as np
def crossover(v1,v2):
N=2
v1n=np.zeros(shape=(1,N+1))
v2n=np.zeros(shape=(1,N+1))
beta=np.random.rand(1)
v1n[0,0]=(1-beta)*v1[0]+beta*v2[0]
v1n[0][1]=v1[1]
v2n[0][0]=(1-beta)*v2[0]+beta*v1[0]
v2n[0][1]=v2[1]
return (v1n,v2n)
when I want to see crossover([3,4],[7,8]), the following error....:
Traceback (most recent call last):
File "<pyshell#82>", line 1, in <module>
crossover([4,5],[5,4])
File "C:\Python27\crossover.py", line 11, in crossover
v1n[0,0]=(1-beta)*v1[0]+beta*v2[0]
TypeError: 'int' object has no attribute '__getitem__'