In GNU Octave, I want to be able to remove specific columns from a matrix. In the interest of generality. I also want to be able to remove specific rows from a matrix.
Suppose I have this:
mymatrix = eye(5)
mymatrix =
Diagonal Matrix
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
I want to remove columns 2 and 4, but when I remove column 2, the position of column 4 has moved to column 3, and that makes my head hurt. There has to be a better way!
GNU Octave delete Columns 2 and 4 from a Matrix
Prints:
GNU Octave delete Rows 2 and 4 from a Matrix:
Prints:
Time complexity
GNU Octave’s CPU complexity for slicing and broadcasting here is a fast linear time
O(n * c)where n is number of rows and c a constant number of rows that remain. It’s C level single-core vectorized but not parallel.Memory complexity
Working memory complexity is linear:
O(n * 2)C makes a clone of the two objects, iterates over every element, then deletes the original.The only time speed will be a problem is if your matrices are unrealistically wide, tall, or have a number of dimensions that blow out your fast memory, and speed is limited by the transfer speed between disk and memory.