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
  • 123,543
  • 24
  • 232
  • 276
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
  • 123,543
  • 24
  • 232
  • 276
  • @user2757745 Glad I could help. Don't forget to [accept an answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235). – arshajii Sep 07 '13 at 21:46