美文网首页AI人工智能与数学之美
Python生成多维双元素列表

Python生成多维双元素列表

作者: KangSmit的算法那些事儿 | 来源:发表于2020-06-15 23:18 被阅读0次
    import numpy as np
    a = [ ]
    for i in range(6):
      for j in range(6):
          a0 = [ i,  j]
          a.append(a0)
    
    b = np.array(a)
    
    

    执行结果:

    b
    Out[3]: 
    array([[0, 0],
           [0, 1],
           [0, 2],
           [0, 3],
           [0, 4],
           [0, 5],
           [1, 0],
           [1, 1],
           [1, 2],
           [1, 3],
           [1, 4],
           [1, 5],
           [2, 0],
           [2, 1],
           [2, 2],
           [2, 3],
           [2, 4],
           [2, 5],
           [3, 0],
           [3, 1],
           [3, 2],
           [3, 3],
           [3, 4],
           [3, 5],
           [4, 0],
           [4, 1],
           [4, 2],
           [4, 3],
           [4, 4],
           [4, 5],
           [5, 0],
           [5, 1],
           [5, 2],
           [5, 3],
           [5, 4],
           [5, 5]])
    
    

    相关文章

      网友评论

        本文标题:Python生成多维双元素列表

        本文链接:https://www.haomeiwen.com/subject/dxpkxktx.html