list(ndarray) != ndarray.tolist()
See original GitHub issueI stumbled over this:
import numpy as np
import json
ndarray = np.array([1, 2, 3], dtype=np.float32)
# works:
json.dumps(ndarray.tolist())
# does not work: json.dumps(list(ndarray))
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
numpy.ndarray.tolist — NumPy v1.24 Manual
numpy.ndarray.tolist#. method. ndarray.tolist()#. Return the array as an a.ndim -levels deep nested list of Python scalars. Return a copy of the array data ......
Read more >Python | Numpy ndarray.tolist() - GeeksforGeeks
With the help of numpy.ndarray.tolist() method, we can have the list of data elements which is converted from an ndarray using ndarray.tolist() ......
Read more >How To Convert a NumPy Array to List in Python - DigitalOcean
With NumPy, np.array objects can be converted to a list with the tolist() function. The tolist() function doesn't accept any arguments.
Read more >How to Convert NumPy Array to List - Spark by {Examples}
How to convert NumPy Array to list in Python? To convert a NumPy array (ndarray) to a Python list use ndarray.tolist() function, this...
Read more >Convert NumPy array to Python list - Stack Overflow
Use tolist() : >>> import numpy as np >>> np.array([[1,2,3],[4,5,6]]).tolist() [[1, 2, 3], [4, 5, 6]]. Note that this converts the values ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah, I thought that there might be a special method similar to
__iter__()
. I guess changing__iter__()
is not an option and probably this is what is used bylist()
?list() is part of Python. It cannot be rewritten to know about every type in existence. I go write the “RogerPy” module, introduce my own types, and list is supposed to know about it? Not possible.
list just iterates over an iterable: ‘return [i for i in x]’
It doesn’t know anything about the underlying type in
x
, it merely requires that it be iterable.