Skip to content

Instantly share code, notes, and snippets.

@blessdyb
Created May 12, 2017 13:42
Show Gist options
  • Save blessdyb/4caa83ce9411f6a205d1f2faf71bab31 to your computer and use it in GitHub Desktop.
Save blessdyb/4caa83ce9411f6a205d1f2faf71bab31 to your computer and use it in GitHub Desktop.
二维不定长数组全排列
import numpy as np
def search(A):
nums = len(A)
max = []
cur = []
for i in range(nums):
max.append(len(A[i]))
cur.append(0)
max = np.array(max)
cur = np.array(cur)
mul = 1
for m in max:
mul = mul*m
result = []
for _ in range(mul):
one = np.zeros(nums)
for i in range(nums):
print(i)
one[i] = A[i][cur[i]]
print(one)
cur[0] += 1
for idx in range(nums-1):
if cur[idx] == max[idx]:
cur[idx] = 0
cur[idx+1] += 1
# print(one)
result.append(one)
return result
if __name__ == '__main__':
A = [[ '1', '2', '3' ], [ '0', '4' ]]
print(len(search(A)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment