हिंदी

Using the arrays created in Question 4 above, write NumPy commands for the following: a) Use NumPy. split() to split the array myarray2 into 5 arrays columnwise.

Advertisements
Advertisements

प्रश्न

Using the arrays created in Question 4 above, write NumPy commands for the following:

  1. Use NumPy. split() to split the array myarray2 into 5 arrays columnwise. Store your resulting arrays in myarray2A, myarray2B, myarray2C, myarray2D and myarray2E. Print the arrays myarray2A, myarray2B, myarray2C, myarray2D and myarray2E.
  2. Split the array zeros at array index 2, 5, 7, 8 and store the resulting arrays in zerosA, zerosB, zerosC and zerosD and print them.
  3. Concatenate the arrays myarray2A, myarray2B and myarray2C into an array having 3 rows and 3 columns.
कोड लेखन
Advertisements

उत्तर

a) 

myarray2A, myarray2B, myarray2C, myarray2D, myarray2E = np.split(myarray2, 5, axis=1)
print("myarray2A:")
print(myarray2A)
print("myarray2B:")
print(myarray2B)
print("myarray2C:")
print(myarray2C)
print("myarray2D:")
print(myarray2D)
print("myarray2E:")
print(myarray2E)

Output:

myarray2A:
[[ 4.]
 [24.]
 [44.]]
myarray2B:
[[ 8.]
 [28.]
 [48.]]
myarray2C:
[[12.]
 [32.]
 [52.]]
myarray2D:
[[16.]
 [36.]
 [56.]]
myarray2E:
[[20.]
 [40.]
 [60.]]

b)

zerosA, zerosB, zerosC, zerosD, zeroE = np.split(zeros, [2, 5, 7, 8])
print("zerosA:\n", zerosA)
print("zerosB:\n", zerosB)
print("zerosC:\n", zerosC)
print("zerosD:\n", zerosD)

Output:

zerosA:
[0. 0.]
zerosB:
[0. 0. 0.]
zerosC:
[0. 0.]
zerosD:
[0.]

c) 

reshaped = np.concatenate((myarray2A, myarray2B, myarray2C), axis=1).reshape(3, 3)
print("Concatenated and Reshaped Array:\n", reshaped)

Output:

Concatenated  and reshaped array:

[[4. 8. 12.]
[24. 28. 32.]
[44. 48. 52.]]
 
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Introduction to NumPy - Exercise [पृष्ठ ११४]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×