matrix

Create a matrix using elements of other matrices in MATLAB

为君一笑 提交于 2020-01-30 10:13:47
问题 I have two matrices a and b (with equal number of columns). I want to create a third matrix c using a condition: For example, I have: a = [1 2 3 4 1 2 3 4 1 2 3 4; 1 1 1 1 2 2 2 2 3 3 3 3] b = [5 6 7 8 9 10 11 12 13 14 15 16; 17 18 19 20 21 22 23 24 25 26 27 28; 29 30 31 32 33 34 35 36 37 38 39 40] The condition is: a(2, :) == 2 , so the resulting matrix should be: c = [1 2 3 4; 2 2 2 2; 9 10 11 12; 21 22 23 24; 33 34 35 36] 回答1: Try this %With your a and b cols = a(2,:) == 2; c = [a(:,cols)

osg中使用MatrixTransform来实现模型的平移/旋转/缩放

不羁的心 提交于 2020-01-30 09:03:09
osg中使用MatrixTransform来实现模型的平移/旋转/缩放 转自:http://www.cnblogs.com/kekec/archive/2011/08/15/2139893.html#undefined MatrixTransform是从Transform - Group继承而来,因此可以在它的下面挂接Node对象。 通过设置其矩阵,来实现其下子节点的模型变换。 -- 用局部坐标系来理解(局部坐标系又称惯性坐标系,其与模型的相对位置在变换的过程中始终不变) 如下代码: // 创建圆柱体 double r = 0.5; double h = 3.0; osg::Vec3 orginPt(0.0, 0.0, 0.0); osg::ref_ptr<osg::Geode> cylinderGeode = new osg::Geode; osg::ref_ptr<osg::Cylinder> geoCylinder = new osg::Cylinder(orginPt, r, h); osg::ref_ptr<osg::ShapeDrawable> cylinderDrawable = new osg::ShapeDrawable(geoCylinder.get()); cylinderDrawable->setColor(osg::Vec4(1.0f,0.0f,0.0f

LeetCode刷题笔记 48. 旋转图像

偶尔善良 提交于 2020-01-30 01:02:11
48. 旋转图像 题目要求 题解 题目要求 给定一个 n × n 的二维矩阵表示一个图像。 将图像顺时针旋转 90 度。 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要使用另一个矩阵来旋转图像。 示例 1: 给定 matrix = [ [ 1,2,3 ] , [ 4,5,6 ] , [ 7,8,9 ] ] , 原地旋转输入矩阵,使其变为: [ [ 7,4,1 ] , [ 8,5,2 ] , [ 9,6,3 ] ] 示例 2: 给定 matrix = [ [ 5, 1, 9,11 ] , [ 2, 4, 8,10 ] , [ 13, 3, 6, 7 ] , [ 15,14,12,16 ] ] , 原地旋转输入矩阵,使其变为: [ [ 15,13, 2, 5 ] , [ 14, 3, 4, 1 ] , [ 12, 6, 8, 9 ] , [ 16, 7,10,11 ] ] 题解 https://github.com/soulmachine/leetcode class Solution { public : void rotate ( vector < vector < int >> & matrix ) { const int n = matrix . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) //

Extraction speed in Matrix package is very slow compared to regular matrix class

≡放荡痞女 提交于 2020-01-29 22:21:26
问题 This is an example of comparing row extraction from large matrices, sparse and dense, using the Matrix package versus the regular R base-matrix class. For dense matrices the speed is almost 395 times faster for the base class matrix : library(Matrix) library(microbenchmark) ## row extraction in dense matrices D1<-matrix(rnorm(2000^2), 2000, 2000) D2<-Matrix(D1) > microbenchmark(D1[1,], D2[1,]) Unit: microseconds expr min lq mean median uq max neval D1[1, ] 14.437 15.9205 31.72903 31.4835 46

Extraction speed in Matrix package is very slow compared to regular matrix class

笑着哭i 提交于 2020-01-29 22:19:40
问题 This is an example of comparing row extraction from large matrices, sparse and dense, using the Matrix package versus the regular R base-matrix class. For dense matrices the speed is almost 395 times faster for the base class matrix : library(Matrix) library(microbenchmark) ## row extraction in dense matrices D1<-matrix(rnorm(2000^2), 2000, 2000) D2<-Matrix(D1) > microbenchmark(D1[1,], D2[1,]) Unit: microseconds expr min lq mean median uq max neval D1[1, ] 14.437 15.9205 31.72903 31.4835 46

Extraction speed in Matrix package is very slow compared to regular matrix class

久未见 提交于 2020-01-29 22:19:27
问题 This is an example of comparing row extraction from large matrices, sparse and dense, using the Matrix package versus the regular R base-matrix class. For dense matrices the speed is almost 395 times faster for the base class matrix : library(Matrix) library(microbenchmark) ## row extraction in dense matrices D1<-matrix(rnorm(2000^2), 2000, 2000) D2<-Matrix(D1) > microbenchmark(D1[1,], D2[1,]) Unit: microseconds expr min lq mean median uq max neval D1[1, ] 14.437 15.9205 31.72903 31.4835 46

Extraction speed in Matrix package is very slow compared to regular matrix class

*爱你&永不变心* 提交于 2020-01-29 22:18:37
问题 This is an example of comparing row extraction from large matrices, sparse and dense, using the Matrix package versus the regular R base-matrix class. For dense matrices the speed is almost 395 times faster for the base class matrix : library(Matrix) library(microbenchmark) ## row extraction in dense matrices D1<-matrix(rnorm(2000^2), 2000, 2000) D2<-Matrix(D1) > microbenchmark(D1[1,], D2[1,]) Unit: microseconds expr min lq mean median uq max neval D1[1, ] 14.437 15.9205 31.72903 31.4835 46

剑指offer:顺时针打印矩阵

时光怂恿深爱的人放手 提交于 2020-01-29 15:08:25
一、题目描述   输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵:   1 2 3 4   5 6 7 8   9 10 11 12   13 14 15 16   则依次打印出数字   1,2,3,4   8,12,16,15   14,13,9,5   6,7,11,10 二、代码 public class Solution { public ArrayList<Integer> printMatrix(int [][] matrix) { ArrayList<Integer> res = new ArrayList<>(); if(matrix.length==0||matrix[0].length==0){ return res; } int sR = 0; int sC = 0; int eR = matrix.length-1; int eC = matrix[0].length-1; while(sR<=eR&&sC<=eC){ printEdge(matrix, sR++, sC++, eR--, eC--, res); } return res; } //打印一圈 public static void printEdge(int[][] matrix,int sR,int sC,int eR,int eC

(3)leetcode--旋转图像

ぃ、小莉子 提交于 2020-01-27 13:37:29
题目: 给定一个 n × n 的二维矩阵表示一个图像。 将图像顺时针旋转 90 度。 说明:你必须在 原地 旋转图像,这意味着你需要直接修改输入的二维矩阵。 请不要 使用另一个矩阵来旋转图像。 示例 1: 给定 matrix = [ [1,2,3], [4,5,6], [7,8,9] ], 原地 旋转输入矩阵,使其变为: [ [7,4,1], [8,5,2], [9,6,3] ] 示例 2: 给定 matrix = [ [ 5, 1, 9,11], [ 2, 4, 8,10], [13, 3, 6, 7], [15,14,12,16] ], 原地 旋转输入矩阵,使其变为: [ [15,13, 2, 5], [14, 3, 4, 1], [12, 6, 8, 9], [16, 7,10,11] ] 解答 : 思路: 将矩阵看作由外而内的一个个环组成,每个环有四个边;则一次将每个边按顺序调换即可;当前环结束后操作下一个环; class Solution { public: void rotate(vector<vector<int>>& matrix) { if(matrix.size()<=0) return; int left=0, right=matrix.size()-1; //由外而内缩小环 while(left<right) { rotateOneByOne(matrix

54. 螺旋矩阵(java)

怎甘沉沦 提交于 2020-01-27 12:04:01
给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。 示例 1: 输入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] 输出: [1,2,3,6,9,8,7,4,5] 示例 2: 输入: [ [1, 2, 3, 4], [5, 6, 7, 8], [9,10,11,12] ] 输出: [1,2,3,4,8,12,11,10,9,5,6,7] 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/spiral-matrix 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 class Solution { public List < Integer > spiralOrder ( int [ ] [ ] matrix ) { ArrayList < Integer > res = new ArrayList < > ( ) ; int m = matrix . length ; if ( m == 0 ) return res ; int n = matrix [ 0 ] . length ; if ( n == 0 ) return res ; int len = Math . max ( m , n ) ; for (