kotlin 查找id_Kotlin程序查找矩阵的转置

kotlin 查找id

A transpose of a matrix is simply a flipped version of the original matrix.
We can transpose a matrix by switching its rows with its columns

矩阵转置只是原始矩阵的翻转形式。
我们可以通过切换矩阵的行和列来转置矩阵

Given a matrix, we have to find its transpose matrix.

给定一个矩阵,我们必须找到它的转置矩阵。

Example:

例:

    Input:
matrix:
[2, 3, 4, 5, 6]
[7, 8, 9, 0, 9]
Output:
Transpose Matrix :
[2, 7]
[3, 8]
[4, 9]
[5, 0]
[6, 9]

在Kotlin中寻找矩阵转置的程序 (Program to find transpose of a matrix in Kotlin)

package com.includehelp
import java.util.*
// Main function, Entry Point of Program
fun main(args: Array<String>) {
//variable of rows and col
val rows: Int
val column: Int
//Input Stream
val scanner = Scanner(System.`in`)
//Input no of rows and column
print("Enter the number of rows and columns of matrix : ")
rows   = scanner.nextInt()
column = scanner.nextInt()
//Create Array
val matrixA     = Array(rows) { IntArray(column) }
val transposeMatrix = Array(column) {IntArray(rows)}
//Input Matrix
println("Enter the Elements of First Matrix ($rows X $column} ): ")
for(i in matrixA.indices){
for(j in matrixA[i].indices){
print("matrixA[$i][$j]: ")
matrixA[i][j]=scanner.nextInt()
}
}
//print Matrix A
println("Matrix A : ")
for(i in matrixA.indices){
println("${matrixA[i].contentToString()} ")
}
//Transpose of Matrix
for(i in transposeMatrix.indices){
for(j in transposeMatrix[i].indices){
transposeMatrix[i][j]=matrixA[j][i]
}
}
//print Transpose Matrix
println("Transpose Matrix : ")
for(i in transposeMatrix.indices){
println("${transposeMatrix[i].contentToString()} ")
}
}

Output

输出量

Run 1:
Enter the number of rows and columns of matrix : 3
4
Enter the Elements of First Matrix (3 X 4} ):
matrixA[0][0]: 2
matrixA[0][1]: 3
matrixA[0][2]: 4
matrixA[0][3]: 5
matrixA[1][0]: 6
matrixA[1][1]: 7
matrixA[1][2]: 8
matrixA[1][3]: 9
matrixA[2][0]: 0
matrixA[2][1]: 1
matrixA[2][2]: 2
matrixA[2][3]: 3
Matrix A :
[2, 3, 4, 5]
[6, 7, 8, 9]
[0, 1, 2, 3]
Transpose Matrix :
[2, 6, 0]
[3, 7, 1]
[4, 8, 2]
[5, 9, 3]
----
Run 2:
Enter the number of rows and columns of matrix : 2
5
Enter the Elements of First Matrix (2 X 5} ):
matrixA[0][0]: 2
matrixA[0][1]: 3
matrixA[0][2]: 4
matrixA[0][3]: 5
matrixA[0][4]: 6
matrixA[1][0]: 7
matrixA[1][1]: 8
matrixA[1][2]: 9
matrixA[1][3]: 0
matrixA[1][4]: 9
Matrix A :
[2, 3, 4, 5, 6]
[7, 8, 9, 0, 9]
Transpose Matrix :
[2, 7]
[3, 8]
[4, 9]
[5, 0]
[6, 9]

翻译自: https://www.includehelp.com/kotlin/find-transpose-of-a-matrix.aspx

kotlin 查找id

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/377967.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[mongodb翻译]分片和故障转移

一个配置恰当的mongodb 分片集群不会有单点失效。 本章节描述了集群服务器中可能出现的故障&#xff0c;及相应的对策。 1. 某个mongos路由进程故障 每一个mongos会运行每一台应用服务器上面&#xff0c;该应用服务器只能通过这个mongos进程和集群进行通信。mongos进程不是…

看张子阳的书真是收获很多,也醒悟了很多(一)

摘录&#xff1a; 这是有一次开会时&#xff0c;我的老总跟我们说了这样一个事例&#xff1a;通常来说&#xff0c;医生是很高尚的职业&#xff08;暂不考虑国内医生的负面新闻&#xff09;&#xff0c;尤其是牙科医生&#xff0c; 他们有着体面的工作并且收入不菲。但是&#…

【C++ grammar】抽象、封装与this指针

目录1、Abstraction and Encapsulation&#xff08;抽象与封装&#xff09;1. Data Field Encapsulation (数据域封装)2. Accessor and Mutator (访问器与更改器)2.1. To read/write private data, we need get/set function (为读写私有数据&#xff0c;需要get/set函数)2.2. …

java创建临时文件_用Java创建一个临时文件

java创建临时文件The task is to create a temporary file in Java. 任务是用Java创建一个临时文件。 Creating a temporary file 创建一个临时文件 To create a temporary file in java – we use createTempFile() method of "File" class. The createTempFile()…

十九、图像的形态学操作

一、图像形态学 图像形态学是图像处理学科的一个单独分支学科 主要针对的是灰度图和二值图像 是由数学的集合论以及数学中的拓扑几何原理发展而来 二、膨胀操作&#xff08;dilate&#xff09; 33的卷积核 以33为卷积核从左往右(从上往下)开始运行&#xff0c;若这卷积核…

X名称空间(WPF)

笔记简述 闲话x名称空间简要x名称空间的Attributex名称空间的标签扩展x名称空间的XAML指令元素闲话 本笔记参考与《深入浅出WPF》、MSDN、Some Blog… MSDN的飞机票点这里。 x名称空间简要 在VS中新建个WpfApplication都会自动生成xmlns:x"http://schemas.microsoft.com/w…

基于Bresenham和DDA算法画线段

直线&#xff1a;ykxb 为了将他在显示屏上显示出来&#xff0c;我们需要为相应的点赋值&#xff0c;那么考虑到计算机的乘法执行效率&#xff0c;我们肯定不会选择用Ykxb这个表达式求值&#xff0c;然后进行画线段。 我们应当是将它转化为加法运算。 下面提供两种常见的算法&am…

leetcode 106. 从中序与后序遍历序列构造二叉树 105. 从前序与中序遍历序列构造二叉树思考分析

目录1、106题目2、参考思路&#xff1a;递归切割数组3、105题目4、同样思路的代码1、106题目 2、参考思路&#xff1a;递归切割数组 代码参考&#xff1a;公众号&#xff1a;代码随想录 后序数组中序数组 以 后序数组(左右中)的最后一个元素作为切割点&#xff0c;先切中序数组…

按频率对元素进行排序

Prerequisite: 先决条件&#xff1a; Hashing data structure 散列数据结构 How to write user-defined comparator for priority queue STL in C? 如何在C 中为优先级队列STL编写用户定义的比较器&#xff1f; How to sort a map based on values instead of value? 如何根…

二十、分水岭算法

一、基本原理 分水岭算法主要是基于距离变换&#xff08;distance transform&#xff09;&#xff0c;找到mark一些种子点&#xff0c;从这些种子点出发根据像素梯度变化进行寻找边缘并标记 分水岭&#xff1a;可以简单的理解成一座山&#xff0c;然后来洪水了&#xff0c;水开…

细数WOW里暴雪的“亲儿子”们

. 不知何时&#xff0c;魔兽世界的词汇中忽然出现了一个新玩意&#xff1a;亲儿子。虽说这个称呼现在大多是拿来调侃法爷的&#xff0c;但江山代有儿子出&#xff0c;各领风骚一两天&#xff0c;今天风光无限的法爷们也经历过被其他职业压得抬不起头的小媳妇生涯。那么今天…

Linux下串口ttyS2,ttyS3不能用的问题解决办法

PC104&#xff0c;Xlinux下&#xff0c;突然发现串口3,4不能用。。。 以为是硬件的问题&#xff0c;换成wince后&#xff0c;3,4工作正常&#xff0c;排除电路问题 在linux下查看dmesg: serial8250: ttyS0 at I/O 0x3f8 (irq 4) is a 16550Aserial8250: ttyS1 at I/O 0x2f8 (i…

安卓log.e函数打印示例_log1p()函数以及C ++中的示例

安卓log.e函数打印示例C log1p()函数 (C log1p() function) log1p() function is a library function of cmath header, it is used to get the natural logarithm (the base-e logarithm) of the one plus given value. It accepts a value (float, double, or long double) …

【C++grammar】C++类数据成员的初始化

目录1、类成员的就地初始化example2、构造函数初始化3、默认构造函数&#xff1a;Default Constructor4、举例5、成员的初始化方法的优先级1、类成员的就地初始化example class S { int m 7; // ok, copy-initializes m int n(7); // 错误&#xff1a;不允许用小括号初始化…

二十一、人脸检测

一、识别图像中的人脸 haarcascade_frontalface_alt_tree.xml lbpcascade_frontalcatface.xml GitHub上有Haar级联检测器源代码可自行下载&#xff0c;lbp级联检测器也一样有源码可自行下载 也一样 import cv2 as cv import numpy as npdef face_detect(image):gray cv.cvtC…

aspx特殊符号说明

http://www.cnblogs.com/GnagWang/archive/2010/07/14/1777130.html转载于:https://www.cnblogs.com/mingyongcheng/archive/2011/11/24/2261253.html

javascript运算符_JavaScript中的按位运算符

javascript运算符JavaScript按位运算符 (JavaScript Bitwise Operators) A lot of times you come across some strange operators where youre knocking your head to understand what is going on in the code. Almost all the programming languages have bitwise operators…

[置顶] Android的IPC访问控制设计与实现

3.3.1 IPC钩子函数设计与实现 IPC Binder是Android最重要的进程间通信机制&#xff0c;因此&#xff0c;必须在此实施强制访问控制。 1. 修改secuirty.h 打开终端shell&#xff0c;输入指令“cd /android4.0/kernel/goldfish/include/linux/vim security.h”&#xff0c;找到结…

TensorFlow在Anaconda环境下创建

一、我使用的是Anaconda自带的Jupyter编译器&#xff0c;详细的安装教程可以参考博文 二、之后打开Jupyter 三、进行测试 我的tensorflow使用的是2.0版本 import tensorflow.compat.v1 as tf tf.disable_v2_behavior()a tf.constant([1.0,2.0],name"a") b tf.co…

leetcode 654. 构造最大二叉树 思考分析

题目 给定一个不含重复元素的整数数组。一个以此数组构建的最大二叉树定义如下&#xff1a; 二叉树的根是数组中的最大元素。 左子树是通过数组中最大值左边部分构造出的最大二叉树。 右子树是通过数组中最大值右边部分构造出的最大二叉树。 通过给定的数组构建最大二叉树&am…