5.2_Cupy_Lab_solution
Cupy Lab
It's your turn again.
In this lab we will work through some fundamental cupy operations.
import cupy as cp1. Create the input data array with the numbers 1 to 500_000_000.
arr = cp.arange(1, 500_000_000)
arr2. Calculate how large the array is in GB with nbytes Hint: GB is 1e9
arr.nbytes / 1e93. How many dimensions does the array have?
arr.ndim4. How many elements does the array have?
arr.size5. What is the shape of the array?
arr.shape6. Create a new array with 5_000_000 elements representing the linear space of 0 to 1000.
arr = cp.linspace(0, 1000, num=5_000_000)
arr7. Create a random array that is 10_000 by 5_000.
arr = cp.random.random((10_000, 5_000))
arr8. Sort that array.
arr = cp.sort(arr)
arrExtra Credit 9. Reshape the array to have one dimension of length 5
arr = arr.reshape(10_000, 1_000, 5)
arr