import itertools
x = [1, 2, 3]
y = [10, 20, 30]
z = [100, 200, 300]
ar=np.array(list(itertools.product(x,y,z))).reshape(len(x),len(y),len(z),-1)
array([[[[ 1, 10, 100],
[ 1, 10, 200],
[ 1, 10, 300]],
[[ 1, 20, 100],
[ 1, 20, 200],
[ 1, 20, 300]],
[[ 1, 30, 100],
[ 1, 30, 200],
[ 1, 30, 300]]],
[[[ 2, 10, 100],
[ 2, 10, 200],
[ 2, 10, 300]],
[[ 2, 20, 100],
[ 2, 20, 200],
[ 2, 20, 300]],
[[ 2, 30, 100],
[ 2, 30, 200],
[ 2, 30, 300]]],
[[[ 3, 10, 100],
[ 3, 10, 200],
[ 3, 10, 300]],
[[ 3, 20, 100],
[ 3, 20, 200],
[ 3, 20, 300]],
[[ 3, 30, 100],
[ 3, 30, 200],
[ 3, 30, 300]]]])
ar.shape
(3, 3, 3, 3)
a=np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
print(a)
b=a.reshape(-1,1)
print(b)
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
[[ 1]
[ 2]
[ 3]
[ 4]
[ 5]
[ 6]
[ 7]
[ 8]
[ 9]
[10]
[11]
[12]
[13]
[14]
[15]]
import numpy as np
import itertools
ind=np.array([[[1,2,3]], [[3,2,4]]])
M=4
lt=np.zeros((len(ind),1,M+1),dtype=int)
for a in range(len(ind)):
lt[a,0,list(itertools.chain(*ind[a]))]+=1
print(lt)
[[[0 1 1 1 0]]
[[0 0 1 1 1]]]
ind.shape
Out[15]: (2, 1, 3)
import itertools
import numpy as np
many_arrays=[np.array([1,2,3]),np.array([4,5,6]), np.array([7,8,9]) ]
many_arrays2=[np.array([1,2,3]),np.array([4,5,6]), np.array([7,8,9]) ]
prd=itertools.product(many_arrays,many_arrays2)
dists=[]
for it in prd:
dists.append([np.linalg.norm(it[0]-it[1]),it[0],it[1]])
sorted(dists, key=lambda x: x[0])
import pandas as pd
import numpy as np
list_a = [[1,2,3,4,5],
[6,7,8,9,10]]
columns = ['a','b','c','d','e']
df_a = pd.DataFrame(list_a, columns=columns)
pd.DataFrame(np.random.rand(3, 2), columns=['foo', 'bar'])