这个结构是二行三列的二维数组
你可以直接切片索引,也可以通过遍历查看具体的结构
import numpy as np
sol_per_pop = 2
initial_pop_weights = []
for curr_sol in np.arange(0, sol_per_pop):
HL1_neurons = 5
input_HL1_weights = np.random.uniform(low=-0.1, high=0.1,
size=(5, HL1_neurons))
HL2_neurons = 3
HL1_HL2_weights = np.random.uniform(low=-0.1, high=0.1,
size=(HL1_neurons, HL2_neurons))
output_neurons = 2
HL2_output_weights = np.random.uniform(low=-0.1, high=0.1,
size=(HL2_neurons, output_neurons))
initial_pop_weights.append(np.array([input_HL1_weights,
HL1_HL2_weights,
HL2_output_weights]))
pop_weights_mat = np.array(initial_pop_weights)
print(pop_weights_mat)
print(pop_weights_mat.shape)
print(pop_weights_mat.ndim)
for i in pop_weights_mat:
for j in i:
for k in j:
print(k)
[-0.08745311 -0.08566917 -0.07634193 -0.01462347 0.08984711] #pop_weights_mat[0][0][0] #pop_weights_mat[0][0]
[-0.05635102 0.00080415 -0.09000382 0.01542581 0.09210149] #pop_weights_mat[0][0][1]
[ 0.01855968 0.01758514 -0.05417793 -0.02632075 0.05365343] #pop_weights_mat[0][0][2]
[ 0.06826839 -0.03431876 -0.09858496 -0.08000008 -0.02817407] #pop_weights_mat[0][0][3]
[-0.02310796 0.00448286 -0.04486132 -0.06270317 -0.07395995] #pop_weights_mat[0][0][4]
[-0.0393707 -0.05913809 0.097642 ] #pop_weights_mat[0][1][0] #pop_weights_mat[0][1]
[-0.0913731 0.01727135 -0.0298622 ] #pop_weights_mat[0][1][1]
[-0.02755238 0.00326942 -0.07739376] #pop_weights_mat[0][1][2]
[-0.07119714 0.02310486 -0.06526119] #pop_weights_mat[0][1][3]
[-0.04077337 0.01515515 0.0304148 ] #pop_weights_mat[0][1][4]
[-0.04630902 -0.07754583] #pop_weights_mat[0][2][0] #pop_weights_mat[0][2]
[-0.02721778 -0.02535745] #pop_weights_mat[0][2][1]
[0.04435848 0.0472513 ] #pop_weights_mat[0][2][2]
#下面的注释不写了
[ 0.00713478 -0.01965951 0.06536753 -0.0119588 -0.06408092] #pop_weights_mat[1][0][0] #pop_weights_mat[1][0]
[-0.04852301 -0.03269899 0.07737023 -0.02743031 -0.09063066]
[ 0.03835544 0.02520843 -0.09607922 -0.04288323 -0.00406102]
[-0.00813421 0.06061313 -0.05698038 0.02934731 0.01555388]
[ 0.0109573 0.02760006 0.03843849 0.02188475 -0.00487984]
[-0.08177725 -0.01318014 0.07974129]
[ 0.00225699 0.07081645 -0.00402112]
[-0.05612385 0.00532562 -0.01333446]
[-0.01793782 0.08433033 -0.04260944]
[ 0.05587896 0.07553454 -0.08745957]
[0.08458351 0.03881342]
[0.04634663 0.02346078]
[-0.06849231 -0.0868095 ]
关于索引你可以看看https://www.numpy.org.cn/user/ba ... 4%E8%B5%8B%E5%80%BC作为参考 |