English

Create the following NumPy arrays: A 2-D array called ones having 2 rows and 5 columns and all the elements are set to 1 and dtype as int.

Advertisements
Advertisements

Question

Create the following NumPy arrays:

A 2-D array called ones having 2 rows and 5 columns and all the elements are set to 1 and dtype as int.

Code Writing
Advertisements

Solution

A 2-D NumPy array called ones having 2 rows and 5 columns, with all elements set to 1 and data type as integer, can be created as follows:

import numpy as np
ones = np.ones((2, 5), dtype=int)
print(ones)

Output:

[[1 1 1 1 1] 
  [1 1 1 1 1]]

Thus, ones is a 2-D array with 2 rows, 5 columns, and integer values of 1.

shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Introduction to NumPy - Exercise [Page 113]

APPEARS IN

NCERT Informatics Practices [English] Class 11
Chapter 6 Introduction to NumPy
Exercise | Q 4. c) | Page 113
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×