Sorting Arrays
Now, let's dive into sorting arrays. Sorting an array involves arranging its elements in a specific order, whether it's ascending, descending, or some other sequence.
Let's try to sort the array:
123456import numpy as np array = np.array([3, -4, 6, 0, 12, 499, -123]) print('unsorted array', array) print('sorted array', np.sort(array))
Note
The
sort()
function returns a copy of the array, while the original array remains unchanged.
Let's try to sort a 2-D array:
12345import numpy as np array = np.array([[-2, 4, -12, -434, 62], [1, 4, 7, 93, 75]]) print('Unsorted array', array) print('Sorted array', np.sort(array))
Swipe to start coding
You have the following array: [15, -2, 33, 47, -55, 16, 0, 834]
. Your task is to sort it.
Løsning
Tak for dine kommentarer!
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 4.76Awesome!
Completion rate improved to 4.76
Sorting Arrays
Now, let's dive into sorting arrays. Sorting an array involves arranging its elements in a specific order, whether it's ascending, descending, or some other sequence.
Let's try to sort the array:
123456import numpy as np array = np.array([3, -4, 6, 0, 12, 499, -123]) print('unsorted array', array) print('sorted array', np.sort(array))
Note
The
sort()
function returns a copy of the array, while the original array remains unchanged.
Let's try to sort a 2-D array:
12345import numpy as np array = np.array([[-2, 4, -12, -434, 62], [1, 4, 7, 93, 75]]) print('Unsorted array', array) print('Sorted array', np.sort(array))
Swipe to start coding
You have the following array: [15, -2, 33, 47, -55, 16, 0, 834]
. Your task is to sort it.
Løsning
Tak for dine kommentarer!
single
Awesome!
Completion rate improved to 4.76
Sorting Arrays
Stryg for at vise menuen
Now, let's dive into sorting arrays. Sorting an array involves arranging its elements in a specific order, whether it's ascending, descending, or some other sequence.
Let's try to sort the array:
123456import numpy as np array = np.array([3, -4, 6, 0, 12, 499, -123]) print('unsorted array', array) print('sorted array', np.sort(array))
Note
The
sort()
function returns a copy of the array, while the original array remains unchanged.
Let's try to sort a 2-D array:
12345import numpy as np array = np.array([[-2, 4, -12, -434, 62], [1, 4, 7, 93, 75]]) print('Unsorted array', array) print('Sorted array', np.sort(array))
Swipe to start coding
You have the following array: [15, -2, 33, 47, -55, 16, 0, 834]
. Your task is to sort it.
Løsning
Tak for dine kommentarer!