class_docstr: This class provides common dispatching and validation logic for indexing.
class_docstr_tok: ["This","class","provides","common","dispatching","and","validation","logic","for","indexing","."]
code: def __setitem__(self, key, x):
      row, col = self._validate_indices(key)
  
      if isinstance(row, INT_TYPES) and isinstance(col, INT_TYPES):
          x = np.asarray(x, dtype=self.dtype)
          if x.size != 1:
              raise ValueError("Trying to assign a sequence to an item")
          self._set_intXint(row, col, x.flat[0])
          return
  
      if isinstance(row, slice):
          row = np.arange(*row.indices(self.shape[0]))[:, None]
      else:
          row = np.atleast_1d(row)
  
      if isinstance(col, slice):
          col = np.arange(*col.indices(self.shape[1]))[None, :]
          if row.ndim == 1:
              row = row[:, None]
      else:
          col = np.atleast_1d(col)
  
      i, j = _broadcast_arrays(row, col)
      if i.shape != j.shape:
          raise IndexError("number of row and column indices differ")
  
      from .base import isspmatrix
  
      if isspmatrix(x):
          if i.ndim == 1:
              # Inner indexing, so treat them like row vectors.
              i = i[None]
              j = j[None]
          broadcast_row = x.shape[0] == 1 and i.shape[0] != 1
          broadcast_col = x.shape[1] == 1 and i.shape[1] != 1
          if not (
              (broadcast_row or x.shape[0] == i.shape[0])
              and (broadcast_col or x.shape[1] == i.shape[1])
          ):
              raise ValueError("shape mismatch in assignment")
          if x.shape[0] == 0 or x.shape[1] == 0:
              return
          x = x.tocoo(copy=True)
          x.sum_duplicates()
          self._set_arrayXarray_sparse(i, j, x)
      else:
          # Make x and i into the same shape
          x = np.asarray(x, dtype=self.dtype)
          if x.squeeze().shape != i.squeeze().shape:
              x = np.broadcast_to(x, i.shape)
          if x.size == 0:
              return
          x = x.reshape(i.shape)
          self._set_arrayXarray(i, j, x)
  
imports: import numpy
  from .sputils import isintlike
label_desc: Use image node_id 2 for calling the IndexMixin obj's underlying member method code with example usage: obj.__setitem__(key, x) without return types