We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Numpy
- Zeros and Ones
- Discussions
Zeros and Ones
Zeros and Ones
Sort by
recency
|
318 Discussions
|
Please Login in order to post a comment
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)
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:
this comment editor is also broken :P (no scrolling when the input exceeds the text box size)
My compact solution…
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')
It's awesome to see learners share tips and insights—makes understanding concepts like shape, dtype, and multidimensional arrays so much easier! 11x play