In case there's any doubt: Nan = Non-numeric datatype for the purposes of this challenge.
Write a program or function that takes a matrix / array as input, as well as a list of column indices.
The challenge is to remove the rows where all elements in the specified columns are Nan. It doesn't matter if other elements in the row are numeric or not. The following examples will hopefully make this more clear (it's one-indexed):
Input array:
16 NaN 3 13
5 11 NaN 8
NaN 7 NaN 12
4 14 -15 1
Input column index: [1 3]
Output array:
16 NaN 3 13
5 11 NaN 8
4 14 -15 1
----
Input array:
16 NaN 3 13
5 11 NaN 8
NaN 7 NaN 12
4 14 -15 1
Input column index: 3
Output array =
16 NaN 3 13
4 14 -15 1
----
Input array:
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
Input column index: 1 2 4
Output array:
[]
Rules and clarifications:
- The matrix will always be non-empty
- The numeric values will be finite, but not necessarily integers or positive values
- The column index vector can be empty (in which case no rows will be removed)
- The column index will never have values exceeding the matrix dimensions
- You can assume there won't be duplicates in the column index list
- You can choose if you want to use zero- or one-indexed values (please specify)
- You can take the input on any convenient format
- Array as list of lists is OK. The column indices can be separate arguments
ans =and similar is accepted in output- You are free to choose what type of non-numeric datatype you want to use
- It should be impossible to perform arithmetic operations with this datatype, or convert it to a finite number using functions such as
float(x).
- It should be impossible to perform arithmetic operations with this datatype, or convert it to a finite number using functions such as
This is code golf, so shortest code in bytes win.