NUMPY创建,填充随机二进制数据

时间:2014-01-28 14:01:02

标签: python arrays numpy

我需要创建一个2D数组。

    import numpy as np
    self.col = 10
    self.row = 5

    ...

    matrix = np.array(self.row, self.col) # NOT WORKING

请使用正确的语法

我还需要用随机二进制数据填充它

1 个答案:

答案 0 :(得分:9)

生成具有二进制值的随机矩阵:

import numpy as np
row, col = 10, 5
matrix = np.random.randint(2, size=(row,col))
相关问题