Angad Sandhu
Search
Browse
On this page

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 cp

1. Create the input data array with the numbers 1 to 500_000_000.

arr = cp.arange(1, 500_000_000)
arr

2. Calculate how large the array is in GB with nbytes Hint: GB is 1e9

arr.nbytes / 1e9

3. How many dimensions does the array have?

arr.ndim

4. How many elements does the array have?

arr.size

5. What is the shape of the array?

arr.shape

6. 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)
arr

7. Create a random array that is 10_000 by 5_000.

arr = cp.random.random((10_000, 5_000))
arr

8. Sort that array.

arr = cp.sort(arr)
arr

Extra Credit 9. Reshape the array to have one dimension of length 5

arr = arr.reshape(10_000, 1_000, 5)
arr

Browse the library