'Point-wise multiplication by another matrix, vector, or
scalar.'

def multiply(self, other):

    if isscalarlike(other):
        return self._mul_scalar(other)
    if isspmatrix(other):
        if (self.shape == other.shape):
            other = self.__class__(other)
            return self._binopt(other, '_elmul_')
        elif (other.shape == (1, 1)):
            return self._mul_scalar(other.toarray()[(0, 0)])
        elif (self.shape == (1, 1)):
            return other._mul_scalar(self.toarray()[(0, 0)])
        elif ((self.shape[1] == 1) and (other.shape[0] == 1)):
            return self._mul_sparse_matrix(other.tocsc())
        elif ((self.shape[0] == 1) and (other.shape[1] == 1)):
            return other._mul_sparse_matrix(self.tocsc())
        elif ((other.shape[0] == 1) and (self.shape[1] == other.shape[1])):
            other = dia_matrix((other.toarray().ravel(), [0]), shape=(other.shape[1], other.shape[1]))
            return self._mul_sparse_matrix(other)
        elif ((self.shape[0] == 1) and (self.shape[1] == other.shape[1])):
            copy = dia_matrix((self.toarray().ravel(), [0]), shape=(self.shape[1], self.shape[1]))
            return other._mul_sparse_matrix(copy)
        elif ((other.shape[1] == 1) and (self.shape[0] == other.shape[0])):
            other = dia_matrix((other.toarray().ravel(), [0]), shape=(other.shape[0], other.shape[0]))
            return other._mul_sparse_matrix(self)
        elif ((self.shape[1] == 1) and (self.shape[0] == other.shape[0])):
            copy = dia_matrix((self.toarray().ravel(), [0]), shape=(self.shape[0], self.shape[0]))
            return copy._mul_sparse_matrix(other)
        else:
            raise ValueError('inconsistent    shapes')
    other = np.atleast_2d(other)
    if (other.ndim != 2):
        return np.multiply(self.toarray(), other)
    if (other.size == 1):
        return self._mul_scalar(other.flat[0])
    elif (self.shape == (1, 1)):
        return np.multiply(self.toarray()[(0, 0)], other)
    from .coo import coo_matrix
    ret = self.tocoo()
    if (self.shape == other.shape):
        data = np.multiply(ret.data, other[(ret.row, ret.col)])
    elif (self.shape[0] == 1):
        if (other.shape[1] == 1):
            data = np.multiply(ret.data, other)
        elif (other.shape[1] == self.shape[1]):
            data = np.multiply(ret.data, other[:, ret.col])
        else:
            raise ValueError('inconsistent    shapes')
        row = np.repeat(np.arange(other.shape[0]), len(ret.row))
        col = np.tile(ret.col, other.shape[0])
        return coo_matrix((data.view(np.ndarray).ravel(), (row, col)), shape=(other.shape[0], self.shape[1]), copy=False)
    elif (self.shape[1] == 1):
        if (other.shape[0] == 1):
            data = np.multiply(ret.data[:, None], other)
        elif (other.shape[0] == self.shape[0]):
            data = np.multiply(ret.data[:, None], other[ret.row])
        else:
            raise ValueError('inconsistent    shapes')
        row = np.repeat(ret.row, other.shape[1])
        col = np.tile(np.arange(other.shape[1]), len(ret.col))
        return coo_matrix((data.view(np.ndarray).ravel(), (row, col)), shape=(self.shape[0], other.shape[1]), copy=False)
    elif ((other.shape[0] == 1) and (self.shape[1] == other.shape[1])):
        data = np.multiply(ret.data, other[:, ret.col].ravel())
    elif ((other.shape[1] == 1) and (self.shape[0] == other.shape[0])):
        data = np.multiply(ret.data, other[ret.row].ravel())
    else:
        raise ValueError('inconsistent    shapes')
    ret.data = data.view(np.ndarray).ravel()
    return ret
