-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathnumpy_zeros_ones.py
71 lines (47 loc) · 1.22 KB
/
numpy_zeros_ones.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
zeros
The zeros tool returns a new array with a given shape and type filled with 0's.
import numpy
print numpy.zeros((1,2)) #Default type is float
#Output : [[ 0. 0.]]
print numpy.zeros((1,2), dtype = numpy.int) #Type changes to int
#Output : [[0 0]]
ones
The ones tool returns a new array with a given shape and type filled with 1's.
import numpy
print numpy.ones((1,2)) #Default type is float
#Output : [[ 1. 1.]]
print numpy.ones((1,2), dtype = numpy.int) #Type changes to int
#Output : [[1 1]]
Task
Your task is to print an array of size N and integer type using the tools zeros and ones. N is the space separated list of the dimensions of the array.
Input Format
A single line containing the space separated list of N.
Output Format
First, print the array using the zeros tool and then print the array with the ones tool.
Sample Input
3 3 3
Sample Output
[[[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]]]
[[[1 1 1]
[1 1 1]
[1 1 1]]
[[1 1 1]
[1 1 1]
[1 1 1]]
[[1 1 1]
[1 1 1]
[1 1 1]]]
"""
import numpy
k = map(int,raw_input().split())
print numpy.zeros(k,dtype = numpy.int)
print numpy.ones(k,dtype = numpy.int)