rohitg00/ai-engineering-from-scratch · error · TypeError
Unsupported type {type(other)}
Error message
Unsupported type {type(other)} What it means
Error "Unsupported type {type(other)}" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at phases/01-math-foundations/12-tensor-operations/code/tensors.py:185
return result
def flatten(self, start_dim=0, end_dim=-1):
if end_dim < 0:
end_dim = self.rank + end_dim
new_shape = (
list(self._shape[:start_dim])
+ [reduce(lambda a, b: a * b, self._shape[start_dim:end_dim + 1], 1)]
+ list(self._shape[end_dim + 1:])
)
return self.reshape(tuple(new_shape))
def _elementwise_op(self, other, op):
if isinstance(other, (int, float)):
result_data = [op(x, other) for x in self._data]
return Tensor(result_data, shape=self._shape)
if not isinstance(other, Tensor):
raise TypeError(f"Unsupported type {type(other)}")
if self._shape != other._shape:
raise ValueError(
f"Shape mismatch: {self._shape} vs {other._shape}. "
"Use broadcast() first."
)
result_data = [op(a, b) for a, b in zip(self._data, other._data)]
return Tensor(result_data, shape=self._shape)
def __add__(self, other):
return self._elementwise_op(other, lambda a, b: a + b)
def __mul__(self, other):
return self._elementwise_op(other, lambda a, b: a * b)
def __sub__(self, other):
return self._elementwise_op(other, lambda a, b: a - b)
def sum(self, axis=None):View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at phases/01-math-foundations/12-tensor-operations/code/tensors.py:185 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/d98fffc895491c62.
Report an issue: GitHub.