1

I tried printing a variable in a python code that I have and I got this:

[array([ 1.,  0.]), array([ 0.,  1.]), array([ 0.,  1.]), array([ 1.,  0.])]

What does this code snippet mean?

3 Answers 3

3

This seems to be a list containing Numpy arrays, although without more information I can't assure that.

>>> from numpy import array
>>> my_var = [array([ 1.,  0.]), array([ 0.,  1.]), array([ 0.,  1.]), array([ 1.,  0.])]
>>> print(my_var)
 [array([ 1.,  0.]), array([ 0.,  1.]), array([ 0.,  1.]), array([ 1.,  0.])]

>>> print(type(my_var)) 
 <type 'list'>
>>> print(type(my_var[0]))
 <type 'numpy.ndarray'>
Sign up to request clarification or add additional context in comments.

1 Comment

You are right about the numpy array! But I had to print using: print(type(my_var[0][0])) otherwise I got for some reason: <type 'list'> That was helpful, thank you!
0

You should best know, what it means. It is a list with four array-objects.

Comments

0

If this is the same array as the one in the built in array module, then the constructor requires a typecode in order to properly initialize the object , in your case like so : array('d', [1. ,0.]) . Are you sure the code you have here works ? Assuming it could infer the typecode from the values passed into the initializer list, you would have a list of arrays

1 Comment

It's almost certainly a list of numpy arrays. One can tell by the specific formatting in repr, which the built-in Python arrays don't do. They would get represented as [array('d', [1.0, 0.0]), ...]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.