请问怎么单独索引图片里面的每个二维矩阵,请大佬们指点
{:5_94:} 请问怎么单独索引图片里面的每个二维矩阵,请大佬们指点{:10_250:} 发代码你发个图片,结构都看不明白 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)
逃兵 发表于 2021-3-5 16:13
发代码
你发个图片,结构都看不明白
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) 这个结构是二行三列的二维数组
你可以直接切片索引,也可以通过遍历查看具体的结构
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.014623470.08984711]#pop_weights_mat#pop_weights_mat
[-0.056351020.00080415 -0.090003820.015425810.09210149]#pop_weights_mat
[ 0.018559680.01758514 -0.05417793 -0.026320750.05365343]#pop_weights_mat
[ 0.06826839 -0.03431876 -0.09858496 -0.08000008 -0.02817407]#pop_weights_mat
[-0.023107960.00448286 -0.04486132 -0.06270317 -0.07395995]#pop_weights_mat
[-0.0393707-0.059138090.097642]#pop_weights_mat#pop_weights_mat
[-0.0913731 0.01727135 -0.0298622 ]#pop_weights_mat
[-0.027552380.00326942 -0.07739376]#pop_weights_mat
[-0.071197140.02310486 -0.06526119]#pop_weights_mat
[-0.040773370.015155150.0304148 ]#pop_weights_mat
[-0.04630902 -0.07754583]#pop_weights_mat#pop_weights_mat
[-0.02721778 -0.02535745]#pop_weights_mat
#pop_weights_mat
#下面的注释不写了
[ 0.00713478 -0.019659510.06536753 -0.0119588-0.06408092]#pop_weights_mat#pop_weights_mat
[-0.04852301 -0.032698990.07737023 -0.02743031 -0.09063066]
[ 0.038355440.02520843 -0.09607922 -0.04288323 -0.00406102]
[-0.008134210.06061313 -0.056980380.029347310.01555388]
[ 0.0109573 0.027600060.038438490.02188475 -0.00487984]
[-0.08177725 -0.013180140.07974129]
[ 0.002256990.07081645 -0.00402112]
[-0.056123850.00532562 -0.01333446]
[-0.017937820.08433033 -0.04260944]
[ 0.055878960.07553454 -0.08745957]
[-0.06849231 -0.0868095 ]
关于索引你可以看看https://www.numpy.org.cn/user/basics/indexing.html#%E4%B8%BA%E7%B4%A2%E5%BC%95%E6%95%B0%E7%BB%84%E8%B5%8B%E5%80%BC作为参考 逃兵 发表于 2021-3-5 17:05
这个结构是二行三列的二维数组
你可以直接切片索引,也可以通过遍历查看具体的结构
可能我没表达清楚 我的意思是想要把这六个矩阵分别整体单独的提取出来{:5_104:} 谢子仲 发表于 2021-3-5 17:46
可能我没表达清楚 我的意思是想要把这六个矩阵分别整体单独的提取出来
明白了 感谢大佬{:5_109:} 谢子仲 发表于 2021-3-5 17:46
可能我没表达清楚 我的意思是想要把这六个矩阵分别整体单独的提取出来
明白了 感谢大佬{:5_109:}
页:
[1]