हिंदी

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

प्रश्न

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

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Introduction to NumPy - Exercise [पृष्ठ ११३]

APPEARS IN

एनसीईआरटी Informatics Practices [English] Class 11
अध्याय 6 Introduction to NumPy
Exercise | Q 4. c) | पृष्ठ ११३
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×