Operation with large matrix

Asked

Viewed 85 times

2

Staff would like to know how I can make the Euclidean distance squared between the octadimensional vectors of b and those who are not in a in a super matrix like this of the example.

I thought so and it didn’t work. Someone has an idea?

I read the whole base:

a = matrix(rnorm(4177*8), ncol = 8)

just to illustrate I took the first 1000:

b = a[1:1000, ]

The function takes the ones that are equal and leaves the different ones:

d = a[!apply(a, 1, function(arow) any(apply(b, 1, function(brow) all(brow==arow)))),]

distancia = t(d - b)%*%(d - b)

But I have the following mistake:

Error in d - b : non-conformable arrays

  • 1

    The error you should receive is not this. Your error message has C, and its headquarters has a name c. Also, it is not a good idea to use native function names, especially one like c(). You should receive another error, by virtue of the matrices c and b are of different sizes.

  • Now that you’ve edited, the error already tells you the problem: You want to subtract matrices of different sizes, there’s something wrong with your math, not your code.

  • I’m checking. Very grateful!

1 answer

0


The question is how to define a matrix a appropriate.

Use:

N=2000
a = matrix(rnorm(N*2*8), ncol = 8)
#b = a[1:N, ]
#para fazer a questão mais desafiadora pode definir b com linhas aleatórias de a
b = a[sample(2*N,N), ]

Your problem would be solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.