|
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.