why type(array(1).tolist()) is int?

hi all, why array(1).tolist() returns 1? I expected to get [1] instead. D.

let me also note that list(array((1))) returns Traceback (innermost last): File "<stdin>", line 1, in <module> TypeError: iteration over a 0-d array D. dmitrey wrote:
hi all, why array(1).tolist() returns 1? I expected to get [1] instead. D.
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion

On 10/1/2008 9:04 AM dmitrey apparently wrote:
why array(1).tolist() returns 1? I expected to get [1] instead.
I guess I would expect it not to work at all. Given that it does work, this seems the best result. What list shape matches the shape of a 0-d array? What is the use case that makes this seem wrong? Alan Isaac

Alan G Isaac wrote:
On 10/1/2008 9:04 AM dmitrey apparently wrote:
why array(1).tolist() returns 1? I expected to get [1] instead.
I guess I would expect it not to work at all. Given that it does work, this seems the best result. What list shape matches the shape of a 0-d array?
What is the use case that makes this seem wrong?
Because I just expect something.tolist() return *Type* list, not *Type* integer. tolist documentation says "Return the array as a list or nested lists" and nothing about possibility to return anything else. As for my situation I store the list in my data field and then call for item from prob.my_list: do_something() D.
Alan Isaac
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
participants (3)
-
Alan G Isaac
-
dmitrey
-
Travis E. Oliphant