Perform the following Single Dimensional Slicing Operations using Numpy array. array1d = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]). Data science using Python in Anaconda - Jupyter
Question
1. from index 4 to last index
2. From index 0 to 4 index
3. From index 4(included) up to index 7(excluded)
4. Excluded last element
5. Up to second last index (negative index)
6. From last to first in reverse order (negative step)
7. All odd numbers in reversed order
8. All even numbers in reversed order
9. All elements
print("Orignal Array: ",array1d,"\n")
print("1. from index 4 to last index: ",array1d[3:])
print("2. From index 0 to 4 index: ",array1d[0:4])
pint("3. From index 4(included) up to index 7(excluded): ",array1d[4::2])
print("4. Excluded last element: ",array1d[0:-2])
print("5. Up to second last index (negative index): ",array1d[0:-2])
print("6. From last to first in reverse order (negative step): ",array1d[::-1])
print("7. All odd numbers in reversed order: ",array1d[-1:0:-2])
print("8. All even numbers in reversed order: ",array1d[-2:0:-2])
print("9. All elements: ",array1d[:])
Orignal Array: [0 1 2 3 4 5 6 7 8 9] 1. from index 4 to last index: [3 4 5 6 7 8 9] 2. From index 0 to 4 index: [0 1 2 3] 3. From index 4(included) up to index 7(excluded): [4 6 8] 4. Excluded last element: [0 1 2 3 4 5 6 7] 5. Up to second last index (negative index): [0 1 2 3 4 5 6 7] 6. From last to first in reverse order (negative step): [9 8 7 6 5 4 3 2 1 0] 7. All odd numbers in reversed order: [9 7 5 3 1] 8. All even numbers in reversed order: [8 6 4 2] 9. All elements: [0 1 2 3 4 5 6 7 8 9]