Skip to content

Optimize flattening: Replace numpy.ndarray.flatten(block) with block.ravel() for better performance and readability #21

@SaFE-APIOpt

Description

@SaFE-APIOpt

flat_directions = numpy.ndarray.flatten(block)

Hi 👋 I came across the following line in the code:
flat_directions = numpy.ndarray.flatten(block)
This can be improved both stylistically and performance-wise by using the .ravel() instance method:
flat_directions =numpy.ndarray.ravel(block)

While both flatten() and ravel() return 1D versions of the array, flatten() always returns a copy of the data, whereas ravel() returns a view if possible, making it faster and more memory-efficient in most cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions