Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Zeros and Ones problem solution in python

YASH PAL, 31 July 2024

In this zero and One’s problem, You are given the shape of the array in the form of space-separated integers, each integer representing the size of different dimensions, your task is to print an array of the given shape and integer type using the tools numpy.zeros and numpy.ones.

HackerRank Zeros and Ones solution in python

Problem solution in Python 2 programming.

import numpy
N = map(int, raw_input().split())
print numpy.zeros(N, dtype = numpy.int)
print numpy.ones(N, dtype = numpy.int)

Problem solution in Python 3 programming.

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

Problem solution in pypy programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT

import numpy

input_number=tuple(map(int,raw_input().strip().split()))
print numpy.zeros(input_number, dtype = numpy.int)
print numpy.ones(input_number, dtype = numpy.int)

Problem solution in pypy3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
import numpy as np
dims = input().split()
dims = [int(i) for i in dims]
print(np.zeros(tuple(dims),dtype=np.int))
print(np.ones(tuple(dims),dtype=np.int))

coding problems python

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes