list as array item and casting problem problem

Hi! All, I have below strange behavior in numpy. Can anyone shed some light on this: I have an array with each item as a list object. You will get this when you use scipy.sparse In [369]: k Out[369]: array([[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]], dtype=object) Assigning value by using slicing is working In [370]: k[0:3] = [[i+3] for i in range(3)] In [371]: k Out[371]: array([[3], [4], [5], [3], [4], [5], [6], [7], [8], [9]], dtype=object) But assigning value by using a list for slicing is NOT In [374]: k[[0, 1,2]] = [[i+3] for i in range(3)] In [375]: k Out[375]: array([3, 4, 5, [3], [4], [5], [6], [7], [8], [9]], dtype=object) You can see those list objects casted to integer. Is this a bug or a feature? if I want to slice it with random index without casting it, what should I do? -- Gen-Nan Chen, Ph. D. email: gnchen@gmail.com
participants (1)
-
Gen-Nan Chen