Zeros and Ones

Sort by

recency

|

318 Discussions

|

  • + 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)

  • + 0 comments

    My compact solution…

    import numpy as np
    
    d = list(map(int, input().split()))
    print(np.zeros(d, int), np.ones(d, int), sep='\n')
    
  • + 0 comments

    import numpy as np x = list(map(int,input().strip().split())) arr1 = np.ones(x,dtype=int) arr2 = np.zeros(x,dtype=int) print(arr2, arr1, sep='\n')

  • + 0 comments

    It's awesome to see learners share tips and insights—makes understanding concepts like shape, dtype, and multidimensional arrays so much easier! 11x play