def as_scalar(tsr):
    """
    Return tensor as scalar.

    :param tsr: Tensor
    :type tsr: numpy.array (4d)
    :return: Scalar
    :rtype: numpy.number
    :raises ValueError: if tensor is not a scalar.
    """
    # check we got a scalar
    if tsr.size != 1:
        raise ValueError('Tensor is not a scalar')
    return tsr.flatten()[0]