(self, key)
return self.__class__(
            backend=self.backend,
            ary=self._tensor[key].reshape(new_shape),
            dtype=self._tensor.dtype,
            base=self)
Extract a subset view of the items via slice style indexing
        along each dimension. e.g. A[5:10, :].  Each slice consists of
        start_idx:stop_idx:step_size triplets.  If step_size isn't specified it
        defaults to 1.  If start_idx isn't specified it defaults to 0.  If
        stop_idx isn't specified it defaults to the total number of elements
        along that dimension.  As such a slice value of ':' allows one to
        select all elements along that dimension. To be consistent with GPU
        Tensors, CPU Tensors remove the axis that has size 1 unless it needs to
        maintain 2D.

        Arguments:
            key (int, slice, tuple): indices of each dimension's slice.

        Returns:
            CPUTensor: view of self corresponding to the subset items.
Extract a subset view of the items via slice style indexing
        along each dimension. e.g. A[5:10, :].  Each slice consists of
        start_idx:stop_idx:step_size triplets.  If step_size isn't specified it
        defaults to 1.  If start_idx isn't specified it defaults to 0.  If
        stop_idx isn't specified it defaults to the total number of elements
        along that dimension.  As such a slice value of ':' allows one to
        select all elements along that dimension. To be consistent with GPU
        Tensors, CPU Tensors remove the axis that has size 1 unless it needs to
        maintain 2D.
Extract a subset view of the items via slice style indexing along each dimension . e . g . A [ 5 : 10 : ] . Each slice consists of start_idx : stop_idx : step_size triplets . If step_size isn t specified it defaults to 1 . If start_idx isn t specified it defaults to 0 . If stop_idx isn t specified it defaults to the total number of elements along that dimension . As such a slice value of : allows one to select all elements along that dimension . To be consistent with GPU Tensors CPU Tensors remove the axis that has size 1 unless it needs to maintain 2D .
def __getitem__(self, key):
        """
        Extract a subset view of the items via slice style indexing
        along each dimension. e.g. A[5:10, :].  Each slice consists of
        start_idx:stop_idx:step_size triplets.  If step_size isn't specified it
        defaults to 1.  If start_idx isn't specified it defaults to 0.  If
        stop_idx isn't specified it defaults to the total number of elements
        along that dimension.  As such a slice value of ':' allows one to
        select all elements along that dimension. To be consistent with GPU
        Tensors, CPU Tensors remove the axis that has size 1 unless it needs to
        maintain 2D.

        Arguments:
            key (int, slice, tuple): indices of each dimension's slice.

        Returns:
            CPUTensor: view of self corresponding to the subset items.

        """
        # speed up common case of [:]
        if not isinstance(key, tuple):
            if key == _none_slice:
                return self
            key = (key,)

        # ensure we return a view
        # exact same behavior as cpu
        # let a.shape = (3,4)
        # a[1,1] = 10 # cpu, gpu and numpy
        # type(a[1,1]) # for cpu and gpu type is Tensor; for numpy type is float
        key_list = list(key)
        for idx, k in enumerate(key):
            if type(k) is int:
                k = self.shape[idx] + k if k < 0 else k
                key_list[idx] = slice(k, k + 1, None)
        key = tuple(key_list)

        new_shape = list(self._tensor[key].shape)
        for idx, k in enumerate(new_shape):
            if len(new_shape) > 2 and k is 1:
                new_shape.remove(k)

        # return a view of the tensor
        return self.__class__(
            backend=self.backend,
            ary=self._tensor[key].reshape(new_shape),
            dtype=self._tensor.dtype,
            base=self)
def __getitem__ ( self , key ) : # speed up common case of [:] if not isinstance ( key , tuple ) : if key == _none_slice : return self key = ( key , ) # ensure we return a view # exact same behavior as cpu # let a.shape = (3,4) # a[1,1] = 10 # cpu, gpu and numpy # type(a[1,1]) # for cpu and gpu type is Tensor; for numpy type is float key_list = list ( key ) for idx , k in enumerate ( key ) : if type ( k ) is int : k = self . shape [ idx ] + k if k < 0 else k key_list [ idx ] = slice ( k , k + 1 , None ) key = tuple ( key_list ) new_shape = list ( self . _tensor [ key ] . shape ) for idx , k in enumerate ( new_shape ) : if len ( new_shape ) > 2 and k is 1 : new_shape . remove ( k ) # return a view of the tensor return self . __class__ ( backend = self . backend , ary = self . _tensor [ key ] . reshape ( new_shape ) , dtype = self . _tensor . dtype , base = self )