How to identify null columns in an array?

Hello, I want a code snippet to detect null columns in my dataset. My desired output is whether any null columns are present or not as shown:

[[2 0 2 0 1 2 0 0 2 1]
[ 0 1 2 0 1 2 2 1 1 0]
[ 0 1 1 0 1 1 0 0 0 1]]

In this 2D matrix, fourth column is entirely null; in such cases, the code will return True .
Can anyone help me with this?

You can utilize NumPy to detect if any null columns are present in an array. Below is a sample code snippet, you can update the 2D matrix accordingly.

Here, we first import the NumPy library and create a 2D array. Then, we check if all elements in each column of the array are equal to zero using np.all(arr == 0, axis=0). This returns a boolean array indicating which columns have all zero elements. Then, we use np.any() to check if any of the columns have all zero elements. If there are any null columns, “has_null_columns” will be True; otherwise, it will be False.