문제

In the matrix

0 1 0 0
1 0 1 0
1 1 0 0
0 0 0 0

I'd like to reshape it by peeling off the 4th column and 4th row into

0 1 0
1 0 1
1 1 0

What is the smart way to go about doing this?

도움이 되었습니까?

해결책

Given a matrix such as:

A←0 1 1 0 1⍀1 0 0 1 1\3 3⍴⍳9

Which is:

0 0 0 0 0
1 0 0 2 3
4 0 0 5 6
0 0 0 0 0
7 0 0 8 9  

Empty rows and columns can be removed with:

(0∨.≠B)/B←(A∨.≠0)⌿A

Output:

1 2 3
4 5 6
7 8 9

Trim only the outsides:

Trim leading and trailing columns:

(∨\0∨.≠B)/B←(⌽∨\⌽0∨.≠A)/A

Trim leading and trailing rows:

(-2↑+/^\⌽B^.=0)↓B←(∨\A∨.≠0)⌿A

All together:

(-2↑+/^\⌽D^.=0)↓D←(∨\C∨.≠0)⌿C←(∨\0∨.≠B)/B←(⌽∨\⌽0∨.≠A)/A
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top