8000 Make it possible to initialize array from dictionary values in Python 3 · Issue #5718 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Make it possible to initialize array from dictionary values in Python 3 #5718
Open
@astrofrog

Description

@astrofrog

At the moment arrays can't be initialized from dictionary values in Python 3:

In [1]: import numpy as np

In [2]: d = {'a':1,'b':2,'c':3}

In [3]: np.array(d.values())
Out[3]: array(dict_values([2, 1, 3]), dtype=object)

and one has to instead explicitly convert to a list first:

In [4]: np.array(list(d.values()))
Out[4]: array([2, 1, 3])

It might be worth adding a special case in the initializer for the array to automatically do this conversion, since d.values() is a valid iterator?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0