Skip to content

Commit d2f59c9

Browse files
authored
feat: remove Image.__array__ (#964)
### Summary of Changes Remove the `Image.__array__` dunder method, which is used if an `Image` object is passed to the `numpy.array` function. Reasons: 1. Integration with specific third-party libraries is out-of-scope so far. 2. If we ever add this, a method `to_numpy_array` would be preferable, since it's more visible and clearer. `__array__` could mean anything.
1 parent e10e6bb commit d2f59c9

File tree

1 file changed

+0
-20
lines changed

1 file changed

+0
-20
lines changed

src/safeds/data/image/containers/_image.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from safeds.exceptions import IllegalFormatError
2424

2525
if TYPE_CHECKING:
26-
from numpy import dtype, ndarray
2726
from torch import Tensor
2827

2928

@@ -174,25 +173,6 @@ def __sizeof__(self) -> int:
174173
"""
175174
return sys.getsizeof(self._image_tensor) + self._image_tensor.element_size() * self._image_tensor.nelement()
176175

177-
def __array__(self, numpy_dtype: str | dtype | None = None) -> ndarray:
178-
"""
179-
Return the image as a numpy array.
180-
181-
Returns
182-
-------
183-
numpy_array:
184-
The image as numpy array.
185-
"""
186-
from numpy import uint8
187-
188-
return (
189-
self._image_tensor.permute(1, 2, 0)
190-
.detach()
191-
.cpu()
192-
.numpy()
193-
.astype(uint8 if numpy_dtype is None else numpy_dtype)
194-
)
195-
196176
def _repr_jpeg_(self) -> bytes | None:
197177
"""
198178
Return a JPEG image as bytes.

0 commit comments

Comments
 (0)