English

Using the arrays created in Question 4 above, write NumPy commands for the following: a) Find the transpose of ones and myarray2. b) Sort the array vowels in reverse.

Advertisements
Advertisements

Question

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

  1. Find the transpose of ones and myarray2.
  2. Sort the array vowels in reverse.
  3. Sort the array myarray1 such that it brings the lowest value of the column in the first row and so on.
Code Writing
Advertisements

Solution

a) 

ones_transpose = ones.transpose()
myarray2_transpose = myarray2.transpose()
print("Transpose of ones:\n", ones_transpose)
print("Transpose of myarray2:\n", myarray2_transpose)

Output:

Traspose of ones:

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

Transpose of myarray2

[[4. 24. 44.]
[8. 28. 48.]
[12. 32. 52.]
[16 36. 56.]
[20. 40. 60.]]

b) 

vowels_reverse_sorted = np.sort(vowels)[::-1]
print("Reverse sorted vowels array:\n", vowels_reverse_sorted)

Output:

Reverse sorted vowels array:
['u' 'o' 'i' 'e' 'a']

c) 

myarray1_sorted = np.sort(myarray1, axis=0)
print("Sorted myarray1:\n", myarray1_sorted)

Output:

[[0. -2 -19]
[2.7 0. 13.]
[10.6 3.4 99.9]]
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Introduction to NumPy - Exercise [Page 114]

APPEARS IN

NCERT Informatics Practices [English] Class 11
Chapter 6 Introduction to NumPy
Exercise | Q 7. | Page 114
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×