鱼C论坛

 找回密码
 立即注册
查看: 1540|回复: 8

[已解决]请问怎么单独索引图片里面的每个二维矩阵,请大佬们指点

[复制链接]
发表于 2021-3-5 16:10:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
1.JPG
最佳答案
2021-3-5 17:05:40
这个结构是二行三列的二维数组

你可以直接切片索引,也可以通过遍历查看具体的结构


  1. import numpy as np

  2. sol_per_pop = 2
  3. initial_pop_weights = []
  4. for curr_sol in np.arange(0, sol_per_pop):
  5.     HL1_neurons = 5
  6.     input_HL1_weights = np.random.uniform(low=-0.1, high=0.1,
  7.                                              size=(5, HL1_neurons))
  8.     HL2_neurons = 3
  9.     HL1_HL2_weights = np.random.uniform(low=-0.1, high=0.1,
  10.                                              size=(HL1_neurons, HL2_neurons))
  11.     output_neurons = 2
  12.     HL2_output_weights = np.random.uniform(low=-0.1, high=0.1,
  13.                                               size=(HL2_neurons, output_neurons))

  14.     initial_pop_weights.append(np.array([input_HL1_weights,
  15.                                                 HL1_HL2_weights,
  16.                                                 HL2_output_weights]))

  17. pop_weights_mat = np.array(initial_pop_weights)
  18. print(pop_weights_mat)
  19. print(pop_weights_mat.shape)
  20. print(pop_weights_mat.ndim)


  21. for i in pop_weights_mat:
  22.     for j in i:
  23.         for k in j:
  24.             print(k)
  25.             
复制代码

  1. [-0.08745311 -0.08566917 -0.07634193 -0.01462347  0.08984711]  #pop_weights_mat[0][0][0]  #pop_weights_mat[0][0]
  2. [-0.05635102  0.00080415 -0.09000382  0.01542581  0.09210149]  #pop_weights_mat[0][0][1]
  3. [ 0.01855968  0.01758514 -0.05417793 -0.02632075  0.05365343]  #pop_weights_mat[0][0][2]
  4. [ 0.06826839 -0.03431876 -0.09858496 -0.08000008 -0.02817407]  #pop_weights_mat[0][0][3]
  5. [-0.02310796  0.00448286 -0.04486132 -0.06270317 -0.07395995]  #pop_weights_mat[0][0][4]
  6. [-0.0393707  -0.05913809  0.097642  ]  #pop_weights_mat[0][1][0]  #pop_weights_mat[0][1]
  7. [-0.0913731   0.01727135 -0.0298622 ]  #pop_weights_mat[0][1][1]
  8. [-0.02755238  0.00326942 -0.07739376]  #pop_weights_mat[0][1][2]
  9. [-0.07119714  0.02310486 -0.06526119]  #pop_weights_mat[0][1][3]
  10. [-0.04077337  0.01515515  0.0304148 ]  #pop_weights_mat[0][1][4]
  11. [-0.04630902 -0.07754583]  #pop_weights_mat[0][2][0]  #pop_weights_mat[0][2]
  12. [-0.02721778 -0.02535745]  #pop_weights_mat[0][2][1]
  13. [0.04435848 0.0472513 ]    #pop_weights_mat[0][2][2]
  14. #下面的注释不写了
  15. [ 0.00713478 -0.01965951  0.06536753 -0.0119588  -0.06408092]  #pop_weights_mat[1][0][0]  #pop_weights_mat[1][0]
  16. [-0.04852301 -0.03269899  0.07737023 -0.02743031 -0.09063066]
  17. [ 0.03835544  0.02520843 -0.09607922 -0.04288323 -0.00406102]
  18. [-0.00813421  0.06061313 -0.05698038  0.02934731  0.01555388]
  19. [ 0.0109573   0.02760006  0.03843849  0.02188475 -0.00487984]
  20. [-0.08177725 -0.01318014  0.07974129]
  21. [ 0.00225699  0.07081645 -0.00402112]
  22. [-0.05612385  0.00532562 -0.01333446]
  23. [-0.01793782  0.08433033 -0.04260944]
  24. [ 0.05587896  0.07553454 -0.08745957]
  25. [0.08458351 0.03881342]
  26. [0.04634663 0.02346078]
  27. [-0.06849231 -0.0868095 ]
复制代码


关于索引你可以看看https://www.numpy.org.cn/user/ba ... 4%E8%B5%8B%E5%80%BC作为参考
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-3-5 16:11:29 | 显示全部楼层
请问怎么单独索引图片里面的每个二维矩阵,请大佬们指点
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-3-5 16:13:22 | 显示全部楼层
发代码

你发个图片,结构都看不明白
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-5 16:32:48 | 显示全部楼层
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)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-5 16:33:32 | 显示全部楼层
逃兵 发表于 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)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-3-5 17:05:40 | 显示全部楼层    本楼为最佳答案   
这个结构是二行三列的二维数组

你可以直接切片索引,也可以通过遍历查看具体的结构


  1. import numpy as np

  2. sol_per_pop = 2
  3. initial_pop_weights = []
  4. for curr_sol in np.arange(0, sol_per_pop):
  5.     HL1_neurons = 5
  6.     input_HL1_weights = np.random.uniform(low=-0.1, high=0.1,
  7.                                              size=(5, HL1_neurons))
  8.     HL2_neurons = 3
  9.     HL1_HL2_weights = np.random.uniform(low=-0.1, high=0.1,
  10.                                              size=(HL1_neurons, HL2_neurons))
  11.     output_neurons = 2
  12.     HL2_output_weights = np.random.uniform(low=-0.1, high=0.1,
  13.                                               size=(HL2_neurons, output_neurons))

  14.     initial_pop_weights.append(np.array([input_HL1_weights,
  15.                                                 HL1_HL2_weights,
  16.                                                 HL2_output_weights]))

  17. pop_weights_mat = np.array(initial_pop_weights)
  18. print(pop_weights_mat)
  19. print(pop_weights_mat.shape)
  20. print(pop_weights_mat.ndim)


  21. for i in pop_weights_mat:
  22.     for j in i:
  23.         for k in j:
  24.             print(k)
  25.             
复制代码

  1. [-0.08745311 -0.08566917 -0.07634193 -0.01462347  0.08984711]  #pop_weights_mat[0][0][0]  #pop_weights_mat[0][0]
  2. [-0.05635102  0.00080415 -0.09000382  0.01542581  0.09210149]  #pop_weights_mat[0][0][1]
  3. [ 0.01855968  0.01758514 -0.05417793 -0.02632075  0.05365343]  #pop_weights_mat[0][0][2]
  4. [ 0.06826839 -0.03431876 -0.09858496 -0.08000008 -0.02817407]  #pop_weights_mat[0][0][3]
  5. [-0.02310796  0.00448286 -0.04486132 -0.06270317 -0.07395995]  #pop_weights_mat[0][0][4]
  6. [-0.0393707  -0.05913809  0.097642  ]  #pop_weights_mat[0][1][0]  #pop_weights_mat[0][1]
  7. [-0.0913731   0.01727135 -0.0298622 ]  #pop_weights_mat[0][1][1]
  8. [-0.02755238  0.00326942 -0.07739376]  #pop_weights_mat[0][1][2]
  9. [-0.07119714  0.02310486 -0.06526119]  #pop_weights_mat[0][1][3]
  10. [-0.04077337  0.01515515  0.0304148 ]  #pop_weights_mat[0][1][4]
  11. [-0.04630902 -0.07754583]  #pop_weights_mat[0][2][0]  #pop_weights_mat[0][2]
  12. [-0.02721778 -0.02535745]  #pop_weights_mat[0][2][1]
  13. [0.04435848 0.0472513 ]    #pop_weights_mat[0][2][2]
  14. #下面的注释不写了
  15. [ 0.00713478 -0.01965951  0.06536753 -0.0119588  -0.06408092]  #pop_weights_mat[1][0][0]  #pop_weights_mat[1][0]
  16. [-0.04852301 -0.03269899  0.07737023 -0.02743031 -0.09063066]
  17. [ 0.03835544  0.02520843 -0.09607922 -0.04288323 -0.00406102]
  18. [-0.00813421  0.06061313 -0.05698038  0.02934731  0.01555388]
  19. [ 0.0109573   0.02760006  0.03843849  0.02188475 -0.00487984]
  20. [-0.08177725 -0.01318014  0.07974129]
  21. [ 0.00225699  0.07081645 -0.00402112]
  22. [-0.05612385  0.00532562 -0.01333446]
  23. [-0.01793782  0.08433033 -0.04260944]
  24. [ 0.05587896  0.07553454 -0.08745957]
  25. [0.08458351 0.03881342]
  26. [0.04634663 0.02346078]
  27. [-0.06849231 -0.0868095 ]
复制代码


关于索引你可以看看https://www.numpy.org.cn/user/ba ... 4%E8%B5%8B%E5%80%BC作为参考
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-5 17:46:39 | 显示全部楼层
逃兵 发表于 2021-3-5 17:05
这个结构是二行三列的二维数组

你可以直接切片索引,也可以通过遍历查看具体的结构

可能我没表达清楚 我的意思是想要把这六个矩阵分别整体单独的提取出来
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-5 18:02:56 | 显示全部楼层
谢子仲 发表于 2021-3-5 17:46
可能我没表达清楚 我的意思是想要把这六个矩阵分别整体单独的提取出来

明白了 感谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-5 18:06:28 | 显示全部楼层
谢子仲 发表于 2021-3-5 17:46
可能我没表达清楚 我的意思是想要把这六个矩阵分别整体单独的提取出来

明白了 感谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-27 05:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表