Skip to content

Fix: AttributeError: module 'numpy' has no attribute 'product' #324

Description

@a-ayesh

Error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[22], line 2
      1 # Visualize events using our custom function
----> 2 tonic.utils.plot_event_grid(events)

File ~/Desktop/local/.venv/lib/python3.11/site-packages/tonic/utils.py:45, in plot_event_grid(events, axis_array, plot_frame_number)
     41 sensor_size_p = len(np.unique(events["p"]))
     42 sensor_size = (sensor_size_x, sensor_size_y, sensor_size_p)
     44 transform = transforms.ToFrame(
---> 45     sensor_size=sensor_size, n_time_bins=np.product(axis_array)
     46 )
     48 frames = transform(events)
     49 fig, axes_array = plt.subplots(*axis_array)

File ~/Desktop/local/.venv/lib/python3.11/site-packages/numpy/__init__.py:795, in __getattr__(attr)
    792     import numpy.char as char
    793     return char.chararray
--> 795 raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")

AttributeError: module 'numpy' has no attribute 'product'

Problem

Tonic is using a deprecated reference for product, now used as prod, in plot_event_grid method in utils.py

Solution

In utils.py replace line:

        transform = transforms.ToFrame(
            sensor_size=sensor_size, n_time_bins=np.product(axis_array)
        )

with line:

    # Use np.prod() instead of deprecated np.product()
    transform = tonic.transforms.ToFrame(
        sensor_size=sensor_size, n_time_bins=np.prod(axis_array)
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions