2
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.

arshajii
  • 127,459
  • 24
  • 238
  • 287
wesley
  • 85
  • 1
  • 1
  • 6

1 Answers1

5

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]
Community
  • 1
  • 1
arshajii
  • 127,459
  • 24
  • 238
  • 287