From 76037e514f0300db9a0712f73e77ad075ca916b0 Mon Sep 17 00:00:00 2001 From: Thomas Viehmann Date: Thu, 1 Jul 2021 14:08:51 +0200 Subject: [PATCH] Use numpy.array with dtype Thank you @radarhere. Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- src/PIL/Image.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 98dfec7269d..6017882aa8c 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -700,10 +700,7 @@ def __array__(self, dtype=None): class ArrayData: __array_interface__ = new - arr = np.array(ArrayData()) - if dtype is not None: - arr = arr.astype(dtype) - return arr + return np.array(ArrayData(), dtype) def __getstate__(self): return [self.info, self.mode, self.size, self.getpalette(), self.tobytes()]