【问题标题】:Multiple Random Matrices in PythonPython中的多个随机矩阵
【发布时间】:2020-10-04 17:51:35
【问题描述】:

如何生成多个不同的这种随机矩阵:

rand_pix_l = np.random.randint(256, size=(5,5))

我希望能够预先定义我得到多少个矩阵,以便稍后循环创建这种网格:

x,y = np.meshgrid(np.linspace(0,1,rand_pix_l.shape[0]),np.linspace(0,1,rand_pix_l.shape[1])) 

对于我生成的每个随机矩阵。

【问题讨论】:

  • 预期输出是什么?
  • rand_pix_l = np.random.randint(256, size=(5, 5, N))?使用 numpy 时避免显式循环

标签: python numpy matrix random


【解决方案1】:
for i in range(#desired_number_of_matrices): 
    rand_pix_l = np.random.randint(256, size=(5,5))
    x,y = np.meshgrid(np.linspace(0,1,rand_pix_l.shape[0]), 
          np.linspace(0,1,rand_pix_l.shape[1])) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-11
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-27
    • 2015-03-23
    相关资源
    最近更新 更多