Skip to content

NumPy 2.x incompatibility: scalar conversion error in crossover probability update #30

Description

@BenjaminZoller

I am using numpy 2.4.1 and get:

Traceback (most recent call last):
File ".../site-packages/pydream/Dream.py", line 468, in estimate_crossover_probabilities
m_loc = int(np.where(self.CR_values == CR)[0])
TypeError: only 0-dimensional arrays can be converted to Python scalars

With NumPy ≥ 2.0, np.where(...)[0] returns a 1-D array (e.g. array([1])), and int(array([1])) raises:
TypeError: only 0-dimensional arrays can be converted to Python scalars

Proposed fix:

  • m_loc = int(np.where(self.CR_values == CR)[0])
  • m_loc = np.where(self.CR_values == CR)[0].item()

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