# First adjust the length of the list of elements, then split into chunks from the last axis to the first def reshape(shape, l):
def reshape(shape, l): if len(shape) == 1: return l else: return [reshape(shape[1:], l[i]) for i in range(shape[0])]
# Make a reduce_first; like APL's ⌿; reduces on the first axis def reduce_first(func, mat):