Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
divide an array into contiguous k sub arrays
def divide(data, n_column=3):
result = []
cur_index = 0
n = len(data)
while cur_index < n/n_column:
result.append(data[cur_index*n_column: (cur_index+1)*n_column])
cur_index += 1
if n%n_column != 0:
result.append(data[cur_index*n_column: (cur_index+1)*n_column])
return result
def divide(data, n_column=3):
result = []
cur_index = 0
n = len(data)
while cur_index <= n//n_column:
arr = data[cur_index*n_column: (cur_index+1)*n_column]
if arr:
result.append(arr)
cur_index += 1
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.