हिंदी

Create a 2-D array called myarray4 using arange() having 14 rows and 3 columns with start value = -1, step size 0.25 having. Split this array row wise into 3 equal parts and print the result.

Advertisements
Advertisements

प्रश्न

Create a 2-D array called myarray4 using arange() having 14 rows and 3 columns with start value = -1, step size 0.25 having. Split this array row wise into 3 equal parts and print the result.

कोड लेखन
Advertisements

उत्तर

import numpy as np
myarray4 = np.arange(-1, -1 + (14 * 3 * 0.25), 0.25).reshape(14, 3)
print("myarray4:")
print(myarray4)
myarray4A, myarray4B, myarray4C = np.array_split(myarray4, 3, axis=0)
print("\nmyarray4A:")
print(myarray4A)
print("\nmyarray4B:")
print(myarray4B)
print("\nmyarray4C:")
print(myarray4C)

Output:

myarray4:
[[-1.   -0.75 -0.5 ]
 [-0.25  0.    0.25]
 [ 0.5   0.75  1.  ]
 [ 1.25  1.5   1.75]
 [ 2.    2.25  2.5 ]
 [ 2.75  3.    3.25]
 [ 3.5   3.75  4.  ]
 [ 4.25  4.5   4.75]
 [ 5.    5.25  5.5 ]
 [ 5.75  6.    6.25]
 [ 6.5   6.75  7.  ]
 [ 7.25  7.5   7.75]
 [ 8.    8.25  8.5 ]
 [ 8.75  9.    9.25]]

myarray4A:
[[-1.   -0.75 -0.5 ]
 [-0.25  0.    0.25]
 [ 0.5   0.75  1.  ]
 [ 1.25  1.5   1.75]
 [ 2.    2.25  2.5 ]]

myarray4B:
[[2.75 3.   3.25]
 [3.5  3.75 4.  ]
 [4.25 4.5  4.75]
 [5.   5.25 5.5 ]
 [5.75 6.   6.25]]

myarray4C:
[[6.5  6.75 7.  ]
 [7.25 7.5  7.75]
 [8.   8.25 8.5 ]
 [8.75 9.   9.25]]
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Introduction to NumPy - Exercise [पृष्ठ ११४]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×