def xarray(shape, yx=[0, 0], th=None):
    """2D array of x values.

    Parameters
    ----------
    shape : tuple of int
      The shape of the resulting array, (y, x).
    yx : tuple of float
      Offset the array to align with this y, x center.
    th : Quantity, optional
      Place the x-axis along this position angle, measured
      counterclockwise from the original x-axis.

    Returns
    -------
    x : ndarray
      An array of x values.

    Examples
    --------
    >>> from sbpy.imageanalysis.utils import xarray
    >>> x = xarray((10, 10))
    >>> x[0, 3]
    3

    """
    import numpy as np
    import astropy.units as u
    y, x = np.indices(shape)[-2:]
    y = y - yx[0]
    x = x - yx[1]
    if th is not None:
        x = x * np.cos(th.to(u.rad).value) + y * np.sin(th.to(u.rad).value)
    return x
