简体   繁体   English

随机矩阵:int()参数必须是字符串或数字,而不是'元组'

[英]Random matrix: int() argument must be a string or a number, not 'tuple'

I am trying to generate a matrix with which is mxn and contains random numbers. 我正在尝试生成一个矩阵,其中包含mxn并包含随机数。 I have produced the following code, but am confused by the error I am receiving. 我已经生成了以下代码,但我对收到的错误感到困惑。 Here is the code I am using: 这是我正在使用的代码:

class MP:
def __init__(self,
          mSize, nSize
             ):
    self.mSize=mSize,
    self.nSize=nSize

def RMatrix(param):
  assert isinstance(param, MP)
  m = int(param.mSize)
  n = int(param.nSize)
  A=np.random.rand(m,n)
  return (np.matrix(A))

I am receiving the error: int() argument must be a string or a number, not 'tuple'. 我收到错误:int()参数必须是字符串或数字,而不是'元组'。 Why are the values being passed as tuple? 为什么值作为元组传递? What is going on here and how can I fix this? 这里发生了什么,我该如何解决这个问题?

Got it. 得到它了。 You have an comma in your init (at self.mSize=mSize**,**) . 你的init中有一个逗号(在self.mSize = mSize **,**)。 Remove that and your code will work fine. 删除它,你的代码将正常工作。

import numpy as np
class MP:
    def __init__(self,
              mSize, nSize
                 ):
        self.mSize=mSize
        self.nSize=nSize

    def RMatrix(param):
      assert isinstance(param, MP)
      m = int(param.mSize)
      n = int(param.nSize)
      A=np.random.rand(m,n)
      return (np.matrix(A))

x=MP(3,3)
print x.RMatrix()

Output: 输出:

[[ 0.88170563  0.56061723  0.71311863]
 [ 0.3550273   0.83179011  0.10337231]
 [ 0.43324567  0.52177816  0.04648175]]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django - int参数必须是字符串或数字,而不是'元组' - django - int argument must be a string or a number, not 'Tuple' TypeError:int()参数必须是字符串或数字,而不是'tuple' - TypeError: int() argument must be a string or a number, not 'tuple' int()参数必须是字符串,类似字节的对象或数字,而不是“元组” - int() argument must be a string, a bytes-like object or a number, not 'tuple' TypeError:int()参数必须是字符串或数字,而不是使用ouchdb-python的“元组” - TypeError: int() argument must be a string or a number, not 'tuple' with couchdb-python int() 参数必须是字符串或数字 - int() argument must be a string or a number TypeError:float()参数必须是字符串或数字,而不是“ tuple” - TypeError: float() argument must be a string or a number, not 'tuple' Python Tesseract:int() 参数必须是字符串、类似字节的对象或数字,而不是“元组” - Python Tesseract: int() argument must be a string, a bytes-like object or a number, not 'tuple` 类型错误:将形状转换为 TensorShape 时出错:int() 参数必须是字符串、类似字节的对象或数字,而不是“元组”。 在蟒蛇 - TypeError: Error converting shape to a TensorShape: int() argument must be a string, a bytes-like object or a number, not 'tuple'. in python 类型错误:将形状转换为 TensorShape 时出错:int() 参数必须是字符串或数字,而不是“元组” - TypeError: Error converting shape to a TensorShape: int() argument must be a string or a number, not 'tuple' TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“元组” - TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM