python-fingerprint-recognition icon indicating copy to clipboard operation
python-fingerprint-recognition copied to clipboard

Remove redundant np.array() conversion for better efficiency

Open SaFE-APIOpt opened this issue 10 months ago • 0 comments

https://github.com/kjanko/python-fingerprint-recognition/blob/65a6ceba509469f3f838fb91e59eb0c5ee1d0a0a/app.py#L12 In the current code: temp0 = numpy.array(invertThin[:]) temp0 = numpy.array(temp0) the second np.array() call is redundant and introduces unnecessary memory allocation and processing overhead. Since temp0 is already a NumPy array after the first line, wrapping it again with numpy.array() simply creates a copy of the same array, which is not needed here and may degrade performance, especially when dealing with large datasets.

If the goal is simply to ensure the data is a NumPy array, a single numpy.array() call is sufficient. Even better, numpy.asarray() can be used to avoid copying if invertThin is already an array: temp0 = numpy.asarray(invertThin) This improves performance while preserving the same functionality. Removing the redundant line would make the code cleaner and more efficient.

SaFE-APIOpt avatar Mar 17 '25 15:03 SaFE-APIOpt