'Hi there, I am trying to find the max consecutive ones but python throws an error
I have tried to implement this code but python just blocks me by saying that ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().
def max_running(n):
   # Initialize result
   c = 0
   # Count the number of iterations to
   # reach x = 0.
   while (n!=0):
      # This operation reduces length
      # of every sequence of 1s by one.
      n = (n & (n << 1))
      c=c+1
   return c
# Driver code
n = sample_converted#array converted into binary file
print("Maximum Length of 1's ::>",max_running(n))
Solution 1:[1]
It should be:
def max_running(n):
   # Initialize result
   c = 0
   # Count the number of iterations to
   # reach x = 0.
   while any(i for i in n):
      # This operation reduces length
      # of every sequence of 1s by one.
      n = (n & (n << 1))
      c=c+1
   return c
# Driver code
n = sample_converted#array converted into binary fild1
print("Maximum Length of 1's ::>",max_running(n))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | 
