matrix

Conjugate transpose operator “.H” in numpy

五迷三道 提交于 2019-12-29 04:38:27
问题 It is very convenient in numpy to use the .T attribute to get a transposed version of an ndarray . However, there is no similar way to get the conjugate transpose. Numpy's matrix class has the .H operator, but not ndarray. Because I like readable code, and because I'm too lazy to always write .conj().T , I would like the .H property to always be available to me. How can I add this feature? Is it possible to add it so that it is brainlessly available every time numpy is imported? (A similar

Initialization of a vector of vectors?

三世轮回 提交于 2019-12-29 04:36:07
问题 Is there a way to initialize a vector of vectors in the same ,quick, manner as you initialize a matrix? typedef int type; type matrix[2][2]= { {1,0},{0,1} }; vector<vector<type> > vectorMatrix; //??? 回答1: For the single vector you can use following: typedef int type; type elements[] = {0,1,2,3,4,5,6,7,8,9}; vector<int> vec(elements, elements + sizeof(elements) / sizeof(type) ); Based on that you could use following: type matrix[2][2]= { {1,0},{0,1} }; vector<int> row_0_vec(matrix[0], matrix[0

Why are quaternions used for rotations?

若如初见. 提交于 2019-12-29 02:17:33
问题 I'm a physicist, and have been learning some programming, and have come across a lot of people using quaternions for rotations instead of writing things in matrix/vector form. In physics, there are very good reasons we don't use quaternions (despite the bizarre story that's occasionally told about Hamilton/Gibbs/etc). Physics requires that our descriptions have good analytic behavior (this has a precisely defined meaning, but in some rather technical ways that go far beyond what's taught in

adding values to diagonals of matrix using element-wise addition in matlab

我的梦境 提交于 2019-12-29 01:45:06
问题 I am writing a script that operates on matrices, and I have run into the problem of needing to add the sum of the diagonals of a previous matrix to the diagonal elements of a new matrix. The code I have so far for this particular function (described in more detail below) is: t = 1; for k = (m-1):-1:-(m-1) C = bsxfun(@plus, diag(B, k), d); g(t) = sum(diag(B, k)); t = t + 1; end where d is a 1x3 array, and C is supposed to be a 3x3 array; however, C is being output as a 1x3 array in such a way

MATLAB - Merge submatrices

女生的网名这么多〃 提交于 2019-12-28 23:37:50
问题 I'm working on an image processing project in MATLAB. In order to preprocess the image more easily, I've divided it in rows and columns, so from a original image (a 2D uint8 matrix), now I have a 3D matrix, like a stack. After processing each block, I want to recompose the image again. The problem is that the number of rows and columns is dynamic, so I can't use (or don't know how to use it here) the cat command or the [firstsubmatrix secondsubmatrix] syntax. By the way, I do the division

Count number of values in matrix within given range

让人想犯罪 __ 提交于 2019-12-28 16:14:52
问题 I have matrix A=[2 3 4 5 6 7; 7 6 5 4 3 2] I want to count how many number of elements have a value greater than 3 and less than 6. 回答1: I can think of a few ways: count = numel(A( A(:)>3 & A(:)<6 )) %# (1) count = length(A( A(:)>3 & A(:)<6 )) %# (2) count = nnz( A(:)>3 & A(:)<6 ) %# (3) count = sum( A(:)>3 & A(:)<6 ) %# (4) Ac = A(:); count = numel(A( Ac>3 & Ac<6 )) %# (5,6,7,8) %# prevents double expansion %# similar for length(), nnz(), sum(), %# in the same order as (1)-(4) count = numel

How to find degenerate rows/columns in a covariance matrix

北慕城南 提交于 2019-12-28 13:36:08
问题 I am using numpy.cov to create a covariance matrix from a dataset of over 400 time series. Using linalg.det gives me a value of zero so matrix is singular. I can use linalg.svd to see that the rank is two less than the number of columns so somewhere in the covariance matrix I have some linear combinations to make the matrix degenerate. I have used corrcoef on the underlying timeseries but no correlation > 0.78 so not obvious there. Can someone suggest a method to determine the location of the

LeetCode Hot-221最大正方形

心已入冬 提交于 2019-12-28 09:43:00
在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积。 示例: 输入: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 输出: 4 动态规划 图来自leetcode官方解题 状态转移方程 dp(i, j)=min(dp(i−1, j), dp(i−1, j−1), dp(i, j−1))+1 代码 class Solution : def maximalSquare ( self , matrix : List [ List [ str ] ] ) - > int : if not matrix or matrix == [ [ ] ] : return 0 dp = [ [ 0 for _ in range ( len ( matrix [ 0 ] ) + 1 ) ] for _ in range ( len ( matrix ) + 1 ) ] max_len = 0 for i in range ( 1 , len ( dp ) ) : for j in range ( 1 , len ( dp [ i ] ) ) : if matrix [ i - 1 ] [ j - 1 ] == '1' : dp [ i ] [ j ] = min ( dp [ i - 1 ] [ j - 1 ] , dp [ i ] [ j

Android: Matrix -> what is the different between preconcat and postconcat?

ぃ、小莉子 提交于 2019-12-28 07:42:09
问题 I'm using Matrix to scale and rotate Bitmaps. Now I'm wondering what the difference between preconcat & postconcat is, or more precisely the difference between: postRotate preRotate setRotate From what I could figure out so far setRotate always overwrites the whole matrix, while with preRotate and postRotate I can apply multiple changes to a matrix (e.g. scaling + rotation). However, either using postRotate or preRotate didn't cause any different results for the cases I used them. 回答1: The

Python 矩阵中的路径

☆樱花仙子☆ 提交于 2019-12-28 06:36:36
题目描述 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子。如果一条路径经过了矩阵中的某一个格子,则之后不能再次进入这个格子。 例如 a b c e s f c s a d e e 这样的3 X 4 矩阵中包含一条字符串"bcced"的路径,但是矩阵中不包含"abcb"路径,因为字符串的第一个字符b占据了矩阵中的第一行第二个格子之后,路径不能再次进入该格子。 a b c e s f c s a d e e 思路 这道题使用回溯法来解决,也是深搜的一种。 对于递归,通常有三个地方需要考虑, 1 是递归的定义,把问题转化为递归,要递归哪些方面。 2 是递归的拆解,如果把问题实际转化成递归问题。 3 是递归的出口,当递归发现解之后,如何返回,如何一步一步返回上一层。 在使用回溯方法的时候,通常会有一个栈来记录搜索过的正确的路径,到达当前一个状态后,会先尝试把当前的节点/状态入栈,如果无解再返回。 针对本问题,具体思路是: 遍历矩阵,找到开头后,开始递归的对问题求解。用index来记录目标字符串的位置,寻找到解以后,就把index+1,尝试无解后回溯到index-1. 因为题目要求同一个格子不允许进入两次,所以再额外构建一个二维矩阵用来记录每个格子是否被访问过。 代码 # -