matrix

Transport matrix is missing in the code behind scipy.stats.wasserstein_distance

落爺英雄遲暮 提交于 2020-12-12 05:40:58
问题 Looking at the comments for the code behind scipy.stats.wasserstein_distance which invokes a function called _cdf_distance(p, u_values, v_values, u_weights=None, v_weights=None) , it says this function implements the following formula: l_p(u, v) = \left( \int_{-\infty}^{+\infty} |U-V|^p \right)^{1/p} However, this is not the Wasserstein distance as I know it since, although I see the distance matrix |U-V| in the above formula comment, the transport matrix is noticeably absent. The transport

Is there a way to prevent copy-on-modify when modifying attributes?

僤鯓⒐⒋嵵緔 提交于 2020-12-05 11:53:07
问题 I am surprised that a copy of the matrix is made in the following code: > (m <- matrix(1:12, nrow = 3)) [,1] [,2] [,3] [,4] [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12 > tracemem(m) [1] "<000001E2FC1E03D0>" > str(m) int [1:3, 1:4] 1 2 3 4 5 6 7 8 9 10 ... > attr(m, "dim") <- 4:3 tracemem[0x000001e2fc1e03d0 -> 0x000001e2fcb05008]: > m [,1] [,2] [,3] [1,] 1 5 9 [2,] 2 6 10 [3,] 3 7 11 [4,] 4 8 12 > str(m) int [1:4, 1:3] 1 2 3 4 5 6 7 8 9 10 ... Is it useful? Is it avoidable? EDIT: I do not have

Why does MATLAB use column-major order? [closed]

可紊 提交于 2020-12-05 10:33:05
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Improve this question I understand that the C language uses row-major order to store arrays, whereas MATLAB uses column-major order. Is there any specific reason for MATLAB choosing column-major order? Does MATLAB gain significantly by opting to arrange multidimensional arrays by

Android get accelerometers on earth coordinate system

江枫思渺然 提交于 2020-12-02 10:34:03
问题 I'd like to get accelerometers on Android and have them on the earth coordinate system, just like on this topic Acceleration from device's coordinate system into absolute coordinate system or here Transforming accelerometer's data from device's coordinates to real world coordinates but these solutions don't work for me. I'm working on Processing. The project is simply to track the phones accelerations in space, no matter how it is (standing, on the side...). I'm new to Android too. I'd

How to transform a shape in VB.NET

无人久伴 提交于 2020-11-29 10:22:25
问题 I'm trying to first draw a shape (which i've done already) and then have it transformed as selected by a user for example, rotated to a certain angle, or scaled, showing this original shape and the newly transformed shape. I've tried the following on trying to rotate: Private Sub paint_box_Paint(sender As Object, e As PaintEventArgs) Handles paint_box.Paint Dim x As Integer = paint_box.Size.Width / 2 Dim y As Integer = paint_box.Size.Height / 2 Dim rect As New Rectangle(x, y, 80, 80) ' Create

R: Vectorize loop to create pairwise matrix

白昼怎懂夜的黑 提交于 2020-11-29 04:11:12
问题 I want to speed up a function for creating a pairwise matrix that describes the number of times an object is selected before and after all other objects, within a set of locations. Here is an example df : df <- data.frame(Shop = c("A","A","A","B","B","C","C","D","D","D","E","E","E"), Fruit = c("apple", "orange", "pear", "orange", "pear", "pear", "apple", "pear", "apple", "orange", "pear", "apple", "orange"), Order = c(1, 2, 3, 1, 2, 1, 2, 1, 2, 3, 1, 1, 1)) In each Shop , Fruit is picked by a

Generating banded matrices using numpy

与世无争的帅哥 提交于 2020-11-28 02:08:31
问题 I'm using the following piece of code to create a banded matrix from a generator g : def banded(g, N): """Creates a `g` generated banded matrix with 'N' rows""" n=len(g) T = np.zeros((N,N+n-1)) for x in range(N): T[x][x:x+n]=g return T The usage is simple as: banded([1,2,3], 3) and it returns [1, 2, 3, 0, 0] [0, 1, 2, 3, 0] [0, 0, 1, 2, 3] It will used mostly to solve a finite difference model with a given stencil for example (-1, 1) Is there a better way to generate that stencil? I could not

Generating banded matrices using numpy

懵懂的女人 提交于 2020-11-28 02:05:14
问题 I'm using the following piece of code to create a banded matrix from a generator g : def banded(g, N): """Creates a `g` generated banded matrix with 'N' rows""" n=len(g) T = np.zeros((N,N+n-1)) for x in range(N): T[x][x:x+n]=g return T The usage is simple as: banded([1,2,3], 3) and it returns [1, 2, 3, 0, 0] [0, 1, 2, 3, 0] [0, 0, 1, 2, 3] It will used mostly to solve a finite difference model with a given stencil for example (-1, 1) Is there a better way to generate that stencil? I could not