[英]Why doesn't “numpy.random.random((a,b))” work?
I am trying to create a matrix that creates a matrix of size a*b. 我正在尝试创建一个矩阵,该矩阵创建大小为a * b的矩阵。
numpy.random.random((2,3)) #this works and creates a matrix of size 2,3
But, 但,
m = input("Enter M: ")
n = input("Enter N: ")
o = input("Enter O: ")
A = numpy.random.random((m,n))
B = numpy.random.random((n,o))
why doesnt this work?? 为什么不起作用?
The problem is that the type of m,n
and o
is str
. 问题是
m,n
和o
的类型是str
。 You need to add int
around input
, as follows: 您需要在
input
周围添加int
,如下所示:
import numpy
m = int(input("Enter M: "))
n = int(input("Enter N: "))
o = int(input("Enter O: "))
A = numpy.random.random((m,n))
B = numpy.random.random((n,o))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.