Memoryview tolist() method is misleading

Consider this:
memoryview(b'x').cast('B', ()).tolist() 120
The return value of to list() is an int, not a list. I suggest to deprecate memoryview.tolist() and .tobytes() methods (soft deprecation - in documentation only) and recommend using list(m) and bytes(m) instead. For the multidimensional (and 0-dimensional) views, I suggest adding an unpack([depth]) method that would unpack a view into a nested list of tuples or subviews. For example a single-byte scalar should unpack as follows:
consistent with
struct.unpack_from(m.format, m) (120,)

On Mon, 3 Sep 2012 11:21:50 -0400 Alexander Belopolsky <alexander.belopolsky@gmail.com> wrote:
Is there any point in 0-dimensional views? Wouldn't it be clearer if we simply mandated a strictly positive number of dimensions? Regards Antoine. -- Software development and contracting: http://pro.pitrou.net

On Mon, Sep 3, 2012 at 12:35 PM, Antoine Pitrou <solipsis@pitrou.net> wrote:
Is there any point in 0-dimensional views? Wouldn't it be clearer if we simply mandated a strictly positive number of dimensions?
0-d arrays (scalars) are very important in numpy and it took a significant effort to get the semantics right. I would argue that in nonnumeric contexts, 0-d case is even more important than 1d. For example, users of ctypes are rarely exposed to arrays, but often see nontrivial scalars.

On Mon, 3 Sep 2012 11:21:50 -0400 Alexander Belopolsky <alexander.belopolsky@gmail.com> wrote:
Is there any point in 0-dimensional views? Wouldn't it be clearer if we simply mandated a strictly positive number of dimensions? Regards Antoine. -- Software development and contracting: http://pro.pitrou.net

On Mon, Sep 3, 2012 at 12:35 PM, Antoine Pitrou <solipsis@pitrou.net> wrote:
Is there any point in 0-dimensional views? Wouldn't it be clearer if we simply mandated a strictly positive number of dimensions?
0-d arrays (scalars) are very important in numpy and it took a significant effort to get the semantics right. I would argue that in nonnumeric contexts, 0-d case is even more important than 1d. For example, users of ctypes are rarely exposed to arrays, but often see nontrivial scalars.
participants (2)
-
Alexander Belopolsky
-
Antoine Pitrou