Skip to content

bincount does not accept complex valued weights #23313

@nheinsdorf

Description

@nheinsdorf

Describe the issue:

Hi,
I'm using bincount to sum up complex values. However, the method does not accept complex valued weights, however that would be a useful usecase for me.

Reproduce the code example:

import numpy as np
w = 1j * array([0.3, 0.5, 0.2, 0.7, 1., -0.6]) # weights
x = array([0, 1, 1, 2, 2, 2])
np.bincount(x,  weights=w)

Error message:

Traceback (most recent call last):
  File "/Users/user/PycharmProjects/project/venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3378, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-74-24012315fdf7>", line 5, in <module>
    np.bincount(x,  weights=w)
  File "<__array_function__ internals>", line 180, in bincount
TypeError: Cannot cast array data from dtype('complex128') to dtype('float64') according to the rule 'safe'

Runtime information:

1.23.3
3.9.6 (default, Oct 18 2022, 12:41:40)
[Clang 14.0.0 (clang-1400.0.29.202)]

Context for the issue:

Happy to make a pull request myself (if I can do it), but I actually wasn't able to find the definition of the bincount method in the repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy