Zeros and Ones

Sort by

recency

|

321 Discussions

|

  • + 0 comments

    For Python3 Platform

    No need to use numpy.int. Just type "int" as this is being accepted in the new versions of numpy module. Hackerrank should take a look at the synopsis they have given for this problem

    import numpy
    
    lst = [*map(int, input().split())]
    
    print(numpy.zeros(lst, dtype=int))
    print(numpy.ones(lst, dtype=int))
    
  • + 0 comments
    import numpy as np
    shape = tuple(map(int,input().split()))
    print(np.zeros(shape,dtype = int))
    print(np.ones(shape,dtype = int))
    
  • + 0 comments

    import numpy as np nums=tuple(map(int,input().split())) print(np.zeros(nums,dtype=int)) print(np.ones(nums,dtype=int))

  • + 0 comments

    import numpy as np x = list(map(int, input().split()))

    l = len(x) if l==3: a = np.zeros((x[0],x[1],x[2]),int) b = np.ones((x[0],x[1],x[2]),int) if l == 4: a = np.zeros((x[0],x[1],x[2],x[3]),int) b = np.ones((x[0],x[1],x[2],x[3]),int) if l == 2: a = np.zeros((x[0],x[1]),int) b = np.ones((x[0],x[1]),int) print(a) print(b)

  • + 0 comments

    Sample code is wrong :P written for python 2 instead of python 3, and either a different version of numpy than what is in the run environment, or a typo for numpy.int

    in any case:

    import numpy
    shape = tuple(int(i) for i in input().split())
    print(np.zeros(shape, int))
    print(np.ones(shape, int))
    

    this comment editor is also broken :P (no scrolling when the input exceeds the text box size)