我需要在 multiplyMatrixByConstant 方法中使用矩阵数组,但我不确定如何

Posted

技术标签:

【中文标题】我需要在 multiplyMatrixByConstant 方法中使用矩阵数组,但我不确定如何【英文标题】:I need to use the matrix array in the multiplyMatrixByConstant method but im not sure how 【发布时间】:2021-03-03 13:28:49 【问题描述】:

我收到multiplyMatrixByConstant(); 的错误消息,说“没有给出与所需形式参数相对应的参数”我不确定要包含哪些内容以允许我在 multiplyMatrixByConstant(); 方法中使用矩阵数组

    public class Program

    public static void Main()
    
        Console.WriteLine("              ----------Welcome to the Matrix Program----------");
        Console.WriteLine("Please select one of the following options:");
        Console.WriteLine("1: The Random Matrix");
        Console.WriteLine("2: The Transpose Matrix");
        Console.WriteLine("3: Multiplying a Matrix by a Constant");
        Console.WriteLine("4: Multiplying Two Matrices");
        Console.Write("Your choice is: ");
        string choice = Console.ReadLine();
        if (choice == "1")
        
            generateMatrix();
        
        else if (choice == "2")
        
            generateTranspose();
        
        else if (choice == "3")
        
            multiplyMatrixByConstant();
        
    

    static int[, ] generateMatrix()
    
        Console.Write("Enter the number of columns: ");
        int c = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter the number of rows: ");
        int r = Convert.ToInt32(Console.ReadLine());
        int[, ] matrix = new int[c, r];
        Random rnd = new Random();
        Console.WriteLine("The Matrix is: ");
        for (int i = 0; i < c; i++)
        
            for (int x = 0; x < r; x++)
            
                matrix[i, x] = rnd.Next(0, 10);
            
        

        for (int i = 0; i < c; i++)
        
            for (int x = 0; x < r; x++)
            
                Console.Write(matrix[i, x] + " ");
            

            Console.WriteLine(" ");
        

        return (matrix);
    

    static void generateTranspose()
    
        Console.Write("Enter the number of columns: ");
        int c = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter the number of rows: ");
        int r = Convert.ToInt32(Console.ReadLine());
        int[, ] matrix = new int[c, r];
        Random rnd = new Random();
        for (int i = 0; i < c; i++)
        
            for (int x = 0; x < r; x++)
            
                matrix[i, x] = rnd.Next(0, 10);
            
        

        for (int i = 0; i < c; i++)
        
            for (int x = 0; x < r; x++)
            
                Console.Write(matrix[i, x] + " ");
            

            Console.WriteLine(" ");
        

        Console.WriteLine("The Transpose is:");
        int[, ] transpose = new int[r, c];
        for (int i = 0; i < c; i++)
        
            for (int x = 0; x < r; x++)
            
                transpose[x, i] = matrix[i, x];
            
        

        for (int i = 0; i < r; i++)
        
            for (int x = 0; x < c; x++)
            
                Console.Write(transpose[i, x] + " ");
            

            Console.WriteLine(" ");
        
    

    static void multiplyMatrixByConstant(int[, ] matrix, int c, int r)
    
        generateMatrix();
        Console.Write(" Enter a Constant to Multiply the Matrix by: ");
        int constant = Convert.ToInt32(Console.ReadLine());
        int[, ] result = new int[c, r];
        for (int i = 0; i < c; i++)
        
            for (int x = 0; x < r; x++)
            
                result[i, x] = matrix[i, x] * constant;
            
        

        for (int i = 0; i < c; i++)
        
            for (int x = 0; x < r; x++)
            
                Console.Write(result[i, x] + " ");
            

            Console.WriteLine(" ");
        
    

【问题讨论】:

请将您在完整堆栈跟踪中遇到的错误添加到问题中。 【参考方案1】:

你需要传入参数,(int[, ] matrix, int c and int r)。

【讨论】:

它说那些在当前上下文中不存在 这些需要自己收入

以上是关于我需要在 multiplyMatrixByConstant 方法中使用矩阵数组,但我不确定如何的主要内容,如果未能解决你的问题,请参考以下文章

我需要帮助在处理中创建下摆线

GraphQL:我需要在我的项目中设置啥?

在 cudaStreamSynchronize 之前我需要 cudaSetDevice 吗?

我是不是需要在需要时手动将每个 *.m 文件添加到我的单元测试目标?

为啥这个程序不允许我在需要时输入信息? [复制]

为啥我需要在迁移学习中预训练权重