How to delete the diagonal elements of a matrix?

777 views
Skip to first unread message

El Afrit Mariem

unread,
Nov 16, 2012, 10:41:08 AM11/16/12
to juli...@googlegroups.com
Hey,

In order to delete the diagonal of a matrix, guarded list comprehensions a la python would be the easiest but Julia does not support it yet.

I tried the matlab syntax too:

r = rand(5,5)
r(1:6:end)=[]
reshape(r,5,4)

which does not work with Julia.

As a temporary solution, I found that:
 
r[eye(5).==0] | v->reshape(v,5,4)

Is there a better solution?

cheers

Mariem

Stefan Karpinski

unread,
Nov 16, 2012, 11:09:57 AM11/16/12
to juli...@googlegroups.com
Can you expand on what you mean by "delete"?
--
 
 
 

Mariem El Afrit

unread,
Nov 16, 2012, 11:17:27 AM11/16/12
to juli...@googlegroups.com
I mean from an (n,n)-object we get an (n,n-1)-object after remooving physically the diagonal elements. 

--
 
 
 



--
Mariem

Stefan Karpinski

unread,
Nov 16, 2012, 1:28:18 PM11/16/12
to juli...@googlegroups.com
I would probably write it as an n by n-1 comprehension.

Filtered comprehensions really only make sense for the 1d case. For other dimensions there's no way to ensure that the resulting shape is an n-rectangle.
--
 
 
 
Reply all
Reply to author
Forward
0 new messages