matrix

Eigen: matrix to quaternion and back have different result

旧巷老猫 提交于 2021-02-08 04:10:34
问题 I use Eigen library to covert matrix to quaternion, but when I turn one of the matrix to quaternion and burn it back, it turn out to be another matrix which is identity matrix. The rotation matrix I use was decomposed from a transform matrix. Eigen::Matrix3f R3d = R.topLeftCorner<3,3>(); *Rquat = R3d; R3d = (*Rquat).normalized().toRotationMatrix(); What may cause this problem? This is the matrix before change to quaternion and This is the matrix when I turn it back form the quaternion 回答1:

symbolic matrix multiplication by Ryacas

99封情书 提交于 2021-02-08 03:38:59
问题 I define two matrices mat1 and mat2 in Sym class which is suitable for Ryacas symbolic computation: library(Ryacas) x <- Sym("x") mat1 <- List( List(x, 2), List(x^3, x)) and mat2 <- List( List(x, x), List(3, 6 * x)) now the question is how I can have the symbolic multiplication of these two matrices by Ryacas package? Thank you in advance. 回答1: Try this: > mat1 * mat2 expression(list(list(x^2 + 6, x^2 + 12 * x), list(x^4 + 3 * x, x^4 + 6 * x^2))) 来源: https://stackoverflow.com/questions

Three js 3D rotation

限于喜欢 提交于 2021-02-07 22:38:49
问题 I have 2 mesh objects. Anchor and Rod. The Anchor rotates around z-axis, as illustrated by the image. The rod is supposed to move only backward and forwards. Here is the image: http://imageshack.us/photo/my-images/841/7a83.png/. But i am stuck with trying to figure out the matrix calculation. For example if the anchor rotates 45degrees, so its facing the x-axis, how can i make the rod still move backwards and forwards? 回答1: For the rotation around z axis : var rotation = new THREE.Matrix4()

Setting values in matrices - Python

有些话、适合烂在心里 提交于 2021-02-07 19:58:56
问题 I made i matrix 5x3 field = [] fields = [] for i in range(0,5): for j in range(0,3): x = 1 field.append(x) fields.append(field) When i want to change one field fields[2][2] = 0 i get this: fields[0][0] = 1 fields[0][1] = 1 fields[0][2] = **0** fields[1][0] = 1 fields[1][1] = 1 fields[1][2] = **0** fields[2][0] = 1 fields[2][1] = 1 fields[2][2] = **0** fields[3][0] = 1 fields[3][1] = 1 fields[3][2] = **0** fields[4][0] = 1 fields[4][1] = 1 fields[4][2] = **0** Instead one change i am getting

Get indices of matrix from upper triangle

£可爱£侵袭症+ 提交于 2021-02-07 18:29:45
问题 I have a symmetric matrix represented as a numpy array, like the following example: [[ 1. 0.01735908 0.01628629 0.0183845 0.01678901 0.00990739 0.03326491 0.0167446 ] [ 0.01735908 1. 0.0213712 0.02364181 0.02603567 0.01807505 0.0130358 0.0107082 ] [ 0.01628629 0.0213712 1. 0.01293289 0.02041379 0.01791615 0.00991932 0.01632739] [ 0.0183845 0.02364181 0.01293289 1. 0.02429031 0.01190878 0.02007371 0.01399866] [ 0.01678901 0.02603567 0.02041379 0.02429031 1. 0.01496896 0.00924174 0.00698689] [

Sort matrix based on its diagonal entries

社会主义新天地 提交于 2021-02-07 17:47:10
问题 First of all I would like to point out that my question is different than this one: Sort a numpy matrix based on its diagonal The question is as follow: Suppose I have a numpy matrix A= 5 7 8 7 2 9 8 9 3 I would like to sort the matrix based on its diagonal and then re-arrange the matrix element based on it. Such that now sorted_A: 2 9 7 9 3 8 7 8 5 Note that: (1). The diagonal is sorted (2). The other elements (non-diagonal) re-adjusted by it. How? because diag(A)= [5,2,3] & diag(sorted_A)=

Fill matrix with loop

我怕爱的太早我们不能终老 提交于 2021-02-07 14:30:33
问题 I am trying to create a matrix n by k with k mvn covariates using a loop. Quite simple but not working so far... Here is my code: n=1000 k=5 p=100 mu=0 sigma=1 x=matrix(data=NA, nrow=n, ncol=k) for (i in 1:k){ x [[i]]= mvrnorm(n,mu,sigma) } What's missing? 回答1: I see several things here: You may want to set the random seed for replicability ( set.seed(20430) ). This means that every time you run the code, you will get exactly the same set of pseudorandom variates. Next, your data will just be

Fill matrix with loop

拟墨画扇 提交于 2021-02-07 14:29:25
问题 I am trying to create a matrix n by k with k mvn covariates using a loop. Quite simple but not working so far... Here is my code: n=1000 k=5 p=100 mu=0 sigma=1 x=matrix(data=NA, nrow=n, ncol=k) for (i in 1:k){ x [[i]]= mvrnorm(n,mu,sigma) } What's missing? 回答1: I see several things here: You may want to set the random seed for replicability ( set.seed(20430) ). This means that every time you run the code, you will get exactly the same set of pseudorandom variates. Next, your data will just be

Fastest way to create and fill huge numpy 2D-array?

主宰稳场 提交于 2021-02-07 13:47:56
问题 I have to create and fill huge ( e.g. 96 Go, 72000 rows * 72000 columns) array with floats in each case that come from mathematical formulas. The array will be computed after. import itertools, operator, time, copy, os, sys import numpy from multiprocessing import Pool def f2(x): # more complex mathematical formulas that change according to values in *i* and *x* temp=[] for i in combine: temp.append(0.2*x[1]*i[1]/64.23) return temp def combinations_with_replacement_counts(n, r): #provide all

Convert Image object to rgb pixel array and back in Flutter

半城伤御伤魂 提交于 2021-02-07 12:48:17
问题 Is there a way to get an image's rgb matrix representation? and vice versa? I would like to perform image masking/filtering on the original image so it needs to be applied to its rgb matrix representation. Currently using this library to get an image from a device: https://pub.dartlang.org/packages/image_picker 回答1: https://pub.dartlang.org/packages/image provides image conversion and manipulation utility functions. 回答2: import 'dart:ui' as ui; import 'package:flutter/material.dart'; // for a