def reward_motion_update(D_up, D_cur, X, R, V):
    "\n    Compute updated positions by averaging reward-based unit vectors for\n    adjustments of the point only. The updated distance matrix represents\n    'desired' updates based on reward learning.\n\n    :D_up: R(N,N_R)-matrix of updated distances between points and rewards\n    :D_cur: R(N,N_R)-matrix of current distances between points and rewards\n    :X: R(N,2)-matrix of current point positions\n    :R: R(N_R,2)-matrix of current reward positions\n    :V: {0,1}(N_R,2)-matrix of current agent-reward visibility\n    :returns: R(N,2)-matrix of updated positions\n    "
    N = len(X)
    N_R = len(R)
    D_shape = (N, N_R)
    if DEBUGGING:
        _check_ndim('X', X, 2)
        _check_ndim('R', R, 2)
        _check_shape('X', X, 2, axis=1)
        _check_shape('R', R, 2, axis=1)
        _check_shape('D_up', D_up, D_shape)
        _check_shape('D_cur', D_cur, D_shape)
        _check_shape('V', V, D_shape)
    XX = empty((N, N_R, 2))
    XX[:] = X[:, AX, :]
    D_inf = (D_up == inf)
    norm = (V * (~ D_inf))
    N = norm.sum(axis=1)
    valid = N.nonzero()[0]
    norm[valid] /= N[(valid, AX)]
    D_up[D_inf] = D_cur[D_inf] = 0.0
    DR = (XX - R[AX])
    DR_norm = hypot(DR[(..., 0)], DR[(..., 1)])
    valid = DR_norm.nonzero()
    DR[valid] /= DR_norm[valid][:, AX]
    return ((norm[(..., AX)] * (D_up - D_cur)[(..., AX)]) * DR).sum(axis=1)
Compute updated positions by averaging reward-based unit vectors for
adjustments of the point only. The updated distance matrix represents
'desired' updates based on reward learning.

:D_up: R(N,N_R)-matrix of updated distances between points and rewards
:D_cur: R(N,N_R)-matrix of current distances between points and rewards
:X: R(N,2)-matrix of current point positions
:R: R(N_R,2)-matrix of current reward positions
:V: {0,1}(N_R,2)-matrix of current agent-reward visibility
:returns: R(N,2)-matrix of updated positions
def reward_motion_update(D_up, D_cur, X, R, V):
    "\n    Compute updated positions by averaging reward-based unit vectors for\n    adjustments of the point only. The updated distance matrix represents\n    'desired' updates based on reward learning.\n\n    :D_up: R(N,N_R)-matrix of updated distances between points and rewards\n    :D_cur: R(N,N_R)-matrix of current distances between points and rewards\n    :X: R(N,2)-matrix of current point positions\n    :R: R(N_R,2)-matrix of current reward positions\n    :V: {0,1}(N_R,2)-matrix of current agent-reward visibility\n    :returns: R(N,2)-matrix of updated positions\n    "
    N = len(X)
    N_R = len(R)
    D_shape = (N, N_R)
    if DEBUGGING:
        _check_ndim('X', X, 2)
        _check_ndim('R', R, 2)
        _check_shape('X', X, 2, axis=1)
        _check_shape('R', R, 2, axis=1)
        _check_shape('D_up', D_up, D_shape)
        _check_shape('D_cur', D_cur, D_shape)
        _check_shape('V', V, D_shape)
    XX = empty((N, N_R, 2))
    XX[:] = X[:, AX, :]
    D_inf = (D_up == inf)
    norm = (V * (~ D_inf))
    N = norm.sum(axis=1)
    valid = N.nonzero()[0]
    norm[valid] /= N[(valid, AX)]
    D_up[D_inf] = D_cur[D_inf] = 0.0
    DR = (XX - R[AX])
    DR_norm = hypot(DR[(..., 0)], DR[(..., 1)])
    valid = DR_norm.nonzero()
    DR[valid] /= DR_norm[valid][:, AX]
    return ((norm[(..., AX)] * (D_up - D_cur)[(..., AX)]) * DR).sum(axis=1)