matrix

compute only upper triangle of matrix

大城市里の小女人 提交于 2020-01-25 03:48:34
问题 I have vector: v1 = c(1,2,3) From this vector I want to create matrix where element on i,j position will be sum of vector members on i,j positions: [,1] [,2] [,3] [1,] 2 3 4 [2,] 3 4 5 [3,] 4 5 6 Questions : i,j and j,i is the same, so there is no reason to compute it 2x for better performance. How to achieve this? How to create also variant which will not compute elements if i == j and simply returns NA instead? I'm not asking for diag(m) <- NA command, I'm asking how to prevent computing

Haskell: Assigning unique char to matrix values if x > 0

℡╲_俬逩灬. 提交于 2020-01-25 00:20:14
问题 So my goal for the program is for it to receive an Int matrix for input, and program converts all numbers > 0 to a unique sequential char, while 0's convert into a '_' (doesn't matter, just any character not in the sequence). eg. main> matrixGroupings [[0,2,1],[2,2,0],[[0,0,2]] [["_ab"],["cd_"],["__e"]] The best I've been able to achieve is [["_aa"],["aa_"],["__a"]] using: matrixGroupings xss = map (map (\x -> if x > 0 then 'a' else '_')) xss As far as I can tell, the issue I'm having is

dangerous behavior of lapack routin zheev [duplicate]

有些话、适合烂在心里 提交于 2020-01-24 21:27:28
问题 This question already has answers here : Incorrect/inconsistent results from zgeev() LAPACK (2 answers) Closed 2 years ago . I stumbled upon an odd behavior when using the lapack routine zheev() . There are two issues which I do not understand 1) One of my global variables seems to be overwritten by zheev() . The following small program shows it: [compiled with gfortran -o test test.f90 -llapack -lblas ] program test implicit none integer, parameter :: dp = 8 integer, parameter :: dim = 3

Logical Arrays - In an assignment A(I) = B, the number of elements in B and I must be the same

落爺英雄遲暮 提交于 2020-01-24 16:46:13
问题 I have three matrices, A, B and C. When B is larger than A, I want to saturate the value with A. It says that the number of elements in I (which is (B > A)) must be the same as the number of elements in A. I checked below and they are the same. >> A = [5 5 5; 5 5 5; 5 5 5]; >> B = [2 2 2; 2 2 2; 2 2 2]; >> C(B > A) = A In an assignment A(I) = B, the number of elements in B and I must be the same. >> numel(B > A) ans = 9 >> numel(A) ans = 9 >> numel(A>B) ans = 9 It is also strange that this

How to calculate the base 2 log of a matrix?

允我心安 提交于 2020-01-24 16:02:43
问题 The only function that I found that calculates the log of the matrix, and not of each component of the matrix, was scipy's logm() function, but it finds the log with base e, I need the base 2 log. 回答1: You can use the change-of-base formula to convert the base of the logarithm: log2(x) = logm(x) / logm(2) Mathematica StackExchange has some more in depth discussion of the math behind this: https://mathematica.stackexchange.com/a/92293 来源: https://stackoverflow.com/questions/54773370/how-to

Writing a function that looks for element in a matrix based on values of columns of data frame

夙愿已清 提交于 2020-01-24 13:20:20
问题 I have a data frame with origin and destination names like the following (I will simplify to make it clearer): Origin Dest Time A B Mon B C Wed C B Fri I also have a distance matrix that finds the distance between places A , B , and C . A B C A 0 8 11 B 8 0 6 C 11 6 0 How would I go about extracting the distance from the distance matrix and inputting it in a separate column (such as df$Distance ) for each row of the data frame? 回答1: You could reflow the data into long format and merge based

questions of transform matrix in VR

笑着哭i 提交于 2020-01-24 12:27:07
问题 I have a problem about matrix transformation in OpenVR api. m_compositor->WaitGetPoses(m_rTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0); in the demo which the openvr gives: const Matrix4 & matDeviceToTracking = m_rmat4DevicePose[ unTrackedDevice ]; Matrix4 matMVP = GetCurrentViewProjectionMatrix( nEye ) * matDeviceToTracking; glUniformMatrix4fv( m_nRenderModelMatrixLocation, 1, GL_FALSE, matMVP.get() ); where GetCurrentViewProjectionMatrix is calculated with Matrix4

Sort a Numpy Python matrix progressively according to rows

馋奶兔 提交于 2020-01-24 11:34:06
问题 I have searched around and tried to find a solution to what seems to be a simple problem, but have come up with nothing. The problem is to sort a matrix based on its columns, progressively. So, if I have a numpy matrix like: import numpy as np X=np.matrix([[0,0,1,2],[0,0,1,1],[0,0,0,4],[0,0,0,3],[0,1,2,5]]) print(X) [[0 0 1 2] [0 0 1 1] [0 0 0 4] [0 0 0 3] [0 1 2 5]] I would like to sort it based on the first column, then the second, the third, and so on, to get a result like: Xsorted=np

Eigen max matrix size for 32 bit applications

拥有回忆 提交于 2020-01-24 10:24:09
问题 So, I'm finding the Eigen package crashes when I try to declare a matrix larger than 10000x10000. I need to declare a matrix like this.. about 13000x13000 elements reliably. I ran a test like: for( int tortureEigen = 1 ; tortureEigen < 50000 ; tortureEigen++ ) { printf( "Torturing Eigen with %dx%d..\n", tortureEigen, tortureEigen ) ; Eigen::MatrixXd m( tortureEigen, tortureEigen ) ; } Crashes on my machine (6 GB RAM) at 14008 elements. I'm kind of disappointed! I thought Eigen was like MATLAB

Replacing indices with an unwanted value with their the nearest index's value that happens to be positive

一笑奈何 提交于 2020-01-24 09:31:49
问题 This question is different from the previous question (How to find indices with a negative value and replace the value with the nearest index's value that happens to be positive?). The previous question was to replace an index's unwanted value with its nearest positive index's value on the same row . This question is to replace the unwanted value with its nearest positive index's value throughout the entire matrix (not only limited to the same row) . If there is more than one index that is