Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove Image.__array__ #964

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/safeds/data/image/containers/_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from safeds.exceptions import IllegalFormatError

if TYPE_CHECKING:
from numpy import dtype, ndarray
from torch import Tensor


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

def __array__(self, numpy_dtype: str | dtype | None = None) -> ndarray:
"""
Return the image as a numpy array.

Returns
-------
numpy_array:
The image as numpy array.
"""
from numpy import uint8

return (
self._image_tensor.permute(1, 2, 0)
.detach()
.cpu()
.numpy()
.astype(uint8 if numpy_dtype is None else numpy_dtype)
)

def _repr_jpeg_(self) -> bytes | None:
"""
Return a JPEG image as bytes.
Expand Down