def column_cycle_array(posterior, amt=None):
"""Also called 'position cycle' by Kloosterman et al.
If amt is an array of the same length as posterior, then
cycle each column by the corresponding amount in amt.
Otherwise, cycle each column by a random amount."""
out = copy.deepcopy(posterior)
rows, cols = posterior.shape
if amt is None:
for col in range(cols):
if np.isnan(np.sum(posterior[:,col])):
continue
else:
out[:,col] = np.roll(posterior[:,col], np.random.randint(1, rows))
else:
if len(amt) == cols:
for col in range(cols):
if np.isnan(np.sum(posterior[:,col])):
continue
else:
out[:,col] = np.roll(posterior[:,col], int(amt[col]))
else:
raise TypeError("amt does not seem to be the correct shape!")
return out
评论列表
文章目录