|
black_pixel_indexes = numpy.transpose(numpy.nonzero(bg <= 150)) |
In the code:
black_pixel_indexes = numpy.transpose(numpy.nonzero(bg <= 150))
a more efficient and clearer alternative is:
black_pixel_indexes = numpy.column_stack(numpy.nonzero(bg <= 150))
Both versions return the same result — a 2D array where each row represents the [row, column] index of pixels meeting the condition. However, numpy.column_stack() is designed specifically for this use case and avoids the extra step of transposing the result, making the intent clearer and execution slightly faster.
This is a minor yet effective code quality and performance improvement.
zheye/evaluate.py
Line 30 in 75049f7
In the code:
black_pixel_indexes = numpy.transpose(numpy.nonzero(bg <= 150))a more efficient and clearer alternative is:
black_pixel_indexes = numpy.column_stack(numpy.nonzero(bg <= 150))Both versions return the same result — a 2D array where each row represents the [row, column] index of pixels meeting the condition. However, numpy.column_stack() is designed specifically for this use case and avoids the extra step of transposing the result, making the intent clearer and execution slightly faster.
This is a minor yet effective code quality and performance improvement.