w3resource

NumPy: Test whether a given 2D array has null columns or not

NumPy: Array Object Exercise-183 with Solution

Write a NumPy program to test whether a given 2D array has null columns or not.

Pictorial Presentation:

Python NumPy: Test whether a given 2D array has null columns or not

Sample Solution:

Python Code:

import numpy as np
print("Original array:")
nums = np.random.randint(0,3,(4,10))
print(nums)
print("\nTest whether the said array has null columns or not:")
print((~nums.any(axis=0)).any())

Sample Output:

Original array:
[[1 2 1 1 1 2 1 1 2 0]
 [1 1 0 0 0 0 2 1 2 0]
 [0 0 2 1 0 2 2 2 2 2]
 [1 1 1 2 0 0 0 0 1 2]]

Test whether the said array has null columns or not:
False

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to subtract the mean of each row of a given matrix.
Next: Write a NumPy program to create an array using generator function that generates 15 integers.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

List comprehension:

>>> m = [x ** 2 for x in range(5)]
>>> m
[0, 1, 4, 9, 16]