저는 파이썬에서 간단한 문장 생성기를 설정하여 가능한 많은 단어 조합을 작성하여 로봇과 관련된 일반적인 이미지 세트를 설명합니다. (그 긴 이야기 : D) 그것은 이런 식으로 뭔가를 출력행렬의 가능한 모든 행 조합을 얻으십시오.
: '사이보그 개념 다운로드의 그림'놀랍게도, 임의 내가 쓴 생성
은 최대 255 개 독특한 조합을 간다. 좀 더 콤보를 만들 수 없습니다 (624 개) 조합 (즉시) 다음은 무한 루프 응답에 일어나,
import numpy
from numpy import matrix
from numpy import linalg
import itertools
from pprint import pprint
import random
m = matrix([
['Robot','Cyborg','Andoid', 'Bot', 'Droid'],
['Character','Concept','Mechanical Person', 'Artificial Intelligence', 'Mascot'],
['Downloadable','Stock','3d', 'Digital', 'Robotics'],
['Clipart','Illustration','Render', 'Image', 'Graphic'],
])
used = []
i = 0
def make_sentence(m, used):
sentence = []
i = 0
while i <= 3:
word = m[i,random.randrange(0,4)]
sentence.append(word)
i = i+1
return ' '.join(sentence)
def is_used(sentence, used):
if sentence not in used:
return False
else:
return True
sentences = []
i = 0
while i <= 1000:
sentence = make_sentence(m, used)
if(is_used(sentence, used)):
continue
else:
sentences.append(sentence)
print str(i) + ' ' +sentence
used.append(sentence)
i = i+1
대신 randrange
의 randint
사용 : 여기에 스크립트입니다.
내가 생각하기에 매트릭스의 모든 가능한 조합을 결정하는 더 적절한 방법이 있습니까?
http://stackoverflow.com/questions/1208118/using-numpy-to-build-an-array-of-all-combinations-of-two-arrays? –