PRINT A VECTOR: NUMPY BASIC EXERCISE 19
Print a vector in numpy ranging from 10 to 50 skipping the first and the last values and print the rest of them.
In this exercise, we are going to print vector values ranging from 10 to 50 skipping the first and last values.
Note: arange([start,] stop[, step,], dtype=None) Return evenly spaced values within a given interval. Values are generated within the half-open interval “[start, stop)“ (in other words, the interval including `start` but excluding `stop`). For integer arguments the function is equivalent to the Python built-in `range` function, but returns an ndarray rather than a list.
Code
import numpy as np arr = np.arange(10,50) print("Initial Array") print(arr) print("Printing all values except first and last values") print(arr[1:-1])
Output
import numpy as np
arr = np.arange(10,50)
print("Initial Array")
print(arr)
print("Printing all values except first and last values")
print(arr[1:-1])