linear-algebra

Difference between c(… %*% …) and sum(… * …)

老子叫甜甜 提交于 2020-07-06 04:32:42
问题 This question is a follow up to the discussion from this answer. What is the difference between using c(... %*% ...) and sum(... * ...) in a group_by() function from dplyr ? Both of these code give the same result: #1 library(dplyr) # 1.0.0 library(tidyr) df1 %>% group_by(Date, Market) %>% group_by(Revenue = c(Quantity %*% Price), TotalCost = c(Quantity %*% Cost), Product, .add = TRUE) %>% summarise(Sold = sum(Quantity)) %>% pivot_wider(names_from = Product, values_from = Sold) #2 library

Difference between c(… %*% …) and sum(… * …)

▼魔方 西西 提交于 2020-07-06 04:32:40
问题 This question is a follow up to the discussion from this answer. What is the difference between using c(... %*% ...) and sum(... * ...) in a group_by() function from dplyr ? Both of these code give the same result: #1 library(dplyr) # 1.0.0 library(tidyr) df1 %>% group_by(Date, Market) %>% group_by(Revenue = c(Quantity %*% Price), TotalCost = c(Quantity %*% Cost), Product, .add = TRUE) %>% summarise(Sold = sum(Quantity)) %>% pivot_wider(names_from = Product, values_from = Sold) #2 library

How to perform element-wise custom function with two matrices of identical dimension

大憨熊 提交于 2020-06-15 18:54:06
问题 Haven't been able to find any information on this. If I have two m x n matrices of identical dimension, is there a way to apply an element-wise function in numpty on them? To illustrate my meaning: Custom function is F(x,y) First Matrix: array([[ a, b], [ c, d], [ e, f]]) Second Matrix: array([[ g, h], [ i, j], [ k, l]]) Is there a way to use the above two matrices in numpy to get the desired output below array([[ F(a,g), F(b,h)], [ F(c,i), F(d,j)], [ F(e,k), F(f,l)]]) I know I could just do

Determine if point is inside triangle in 3D

房东的猫 提交于 2020-06-12 04:53:29
问题 I am looking for acknowledgement on my perception of a method regarding determining whether a point is located inside a triangle or not in 3D. Given a ray in the form R(t) = e + td and a set of three points T = {V0, V1, V2} that forms a triangle in three dimensions, I know how to find the parametic equation for the plane that the three points form and how to determine if the ray intersects this plane or not. Lastly, if it intersects, I want to know if the intersection point actually is within

Implementing the Bartels–Stewart algorithm in Eigen3 — real matrices only?

核能气质少年 提交于 2020-05-31 04:41:06
问题 The bounty expires in 5 days . Answers to this question are eligible for a +50 reputation bounty. Charlie wants to draw more attention to this question. Based off this question and solution -- Implementing the Bartels–Stewart algorithm in Eigen3? -- I am trying to solve Lyapunov equations (AX + XA^T = C) using the Eigen library, but am limited to real matrices. The R (with c++) code below works, but involves complex numbers. It can definitely be simplified (since in this framing, there is no