def CostFunction(A):
return sum(A)
A = [[1,1,1],[2,2,2]]
print CostFunction(A[0:])
The answer should be 3, but there should be something wrong with A.
def CostFunction(A):
return sum(A)
A = [[1,1,1],[2,2,2]]
print CostFunction(A[0:])
The answer should be 3, but there should be something wrong with A.
A[0:] is a slice, not an element:
>>> A = [[1,1,1],[2,2,2]]
>>> A[0:]
[[1, 1, 1], [2, 2, 2]]
More generally, A[n:] returns the elements of A from index n to the end of the list. See Python's slice notation for more details.
I believe you want A[0]:
>>> A[0]
[1, 1, 1]