私はいくつかの簡単な質問がありますが、答えを見つけることができません。それらは、次の例のコードで両方とも記述されています。何か助けてくれてありがとう!多次元要素を形状変更せずにnumpy配列に追加する
import numpy as np
#here are two arrays to join together
a = np.array([1,2,3,4,5])
b = np.array([6,7,8,9,10])
#here comes the joining step I don't know how to do better
#QUESTION 1: How to form all permutations of two 1D arrays?
temp = np.array([]) #empty array to be filled with values
for aa in a:
for bb in b:
temp = np.append(temp,[aa,bb]) #fill the array
#QUESTION 2: Why do I have to reshape? How can I avoid this?
temp = temp.reshape((int(temp.size/2),2))
編集:作られたコードより最小限
したがって、すべての順列を形成するという目的を達成するためのあなたのルーパートはありませんか? – Divakar
はい、確かにこれを行うにはクリーンな方法がありますか?私はnumpyで配列をループするのを避けようとしています。使用できるnp.zip()のようなアプリケーションがありますか? – kevinkayaks