566.reshape-the-matrix

在MATLAB中,有一个非常有用的函数 reshape,它可以将一个矩阵重塑为另一个大小不同的新矩阵,但保留其原始数据。

给出一个由二维数组表示的矩阵,以及两个正整数rc,分别表示想要的重构的矩阵的行数和列数。

重构后的矩阵需要将原始矩阵的所有元素以相同的行遍历顺序填充。

如果具有给定参数的reshape操作是可行且合理的,则输出新的重塑矩阵;否则,输出原始矩阵。

示例 1:

输入: 
nums = 
[[1,2],
 [3,4]]
r = 1, c = 4
输出: 
[[1,2,3,4]]
解释:
行遍历nums的结果是 [1,2,3,4]。新的矩阵是 1 * 4 矩阵, 用之前的元素值一行一行填充新矩阵。

示例 2:

输入: 
nums = 
[[1,2],
 [3,4]]
r = 2, c = 4
输出: 
[[1,2],
 [3,4]]
解释:
没有办法将 2 * 2 矩阵转化为 2 * 4 矩阵。 所以输出原矩阵。

解题思路:

    先计算原数组的行列数相乘与新数组的行列数相乘的积是否相等,若不等则直接返回原数组,否则遍历一遍原数组将所有数移动到新的数组中去


解题代码:

    

        m=len(nums)
        n=len(nums[0])
        if r*c!=m*n:
            return nums
        ans=[[0]*c for _ in range(r)]
        for i in range(r*c):
            ans[i/c][i%c]=nums[i/n][i%n]
        return ans

    


rosrun ORB_SLAM3 Stereo_Inertial Vocabulary/ORBvoc.txt Examples/Stereo-Inertial/EuRoC.yaml true ORB-SLAM3 Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. ORB-SLAM2 Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza. This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under certain conditions. See LICENSE.txt. Input sensor was set to: Stereo-Inertial Loading settings from Examples/Stereo-Inertial/EuRoC.yaml Camera1.k3 optional parameter does not exist... -Loaded camera 1 Camera2.k3 optional parameter does not exist... -Loaded camera 2 Camera.newHeight optional parameter does not exist... Camera.newWidth optional parameter does not exist... -Loaded image info IMU.InsertKFsWhenLost optional parameter does not exist... -Loaded IMU calibration -Loaded ORB settings -Loaded viewer settings System.LoadAtlasFromFile optional parameter does not exist... System.SaveAtlasToFile optional parameter does not exist... -Loaded Atlas settings System.thFarPoints optional parameter does not exist... -Loaded misc parameters -Computed rectification maps ---------------------------------- SLAM settings: -Camera 1 parameters (Pinhole): [ 458.654 457.296 367.215 248.375 ] -Camera 1 distortion parameters: [ -0.283408 0.0739591 0.00019359 1.76187e-05 ] -Camera 2 parameters (Pinhole: [ 457.587 456.134 379.999 255.238 ] -Camera 1 distortion parameters: [ -0.283684 0.0745128 -0.00010473 -3.55591e-05 ] -Original image size: [ 752 , 480 ] -Current image size: [ 752 , 480 ] -Camera 1 parameters after rectification: [ 456.715 456.715 364.526 257.269 ] -Sequence FPS: 20 -Stereo baseline: 0.110078 -Stereo depth threshold : 60 -Gyro noise: 0.00017 -Accelerometer noise: 0.002 -Gyro walk: 1.9393e-05 -Accelerometer walk: 0.003 -IMU frequency: 200 -Features per image: 1200 -ORB scale factor: 1.2 -ORB number of scales: 8 -Initial FAST threshold: 20 -Min FAST threshold: 7 Loading ORB Vocabulary. This could take a while... Vocabulary loaded! Initialization of Atlas from scratch Creation of new map with id: 0 Creation of new map with last KF id: 0 Seq. Name: There are 1 cameras in the atlas Camera 0 is pinhole ERROR: Calibration parameters to rectify stereo are missing!
最新发布
09-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值