Question 1
Create a 1D NumPy array from the list `[10, 20, 30, 40]`.
Question 2
Create a 2D array from a nested list `[[1, 2], [3, 4]]`.
Question 3
Create a 3D array using nested lists.
Question 4
Create an array of floats `[1.5, 2.5, 3.5]`.
Question 5
Create a 1D array from a tuple `(100, 200, 300)`.
Question 6
Create an array from `[1, 2, 3]` and force the dtype to `float`.
Question 7
Create an array from `[1.1, 2.2, 3.3]` and force the dtype to `int`.
Question 8
Create a 1D array of strings `['apple', 'banana']`.
Question 9
Create an array of boolean values `[True, False, True]`.
Question 10
Create a 2D array and explicitly set its `dtype` to `complex`.
Question 11
Create an array of 5 zeros.
Question 12
Create a 3x3 array of zeros.
Question 13
Create a 2x4 array of zeros with integer data type.
Question 14
Create an array of 10 ones.
Question 15
Create a 4x4 matrix of ones.
Question 16
Create a 3x2 matrix of ones with boolean data type.
Question 17
Create an uninitialized (empty) 1D array of size 5.
Question 18
Create an empty 2x2 matrix.
Question 19
Create an empty 3x3 matrix with integer data type.
Question 20
Why might `np.empty()` be faster than `np.zeros()`?
Question 21
Create an array of numbers from 0 to 9 using `arange`.
Question 22
Create an array of numbers from 10 to 19 using `arange`.
Question 23
Create an array of even numbers from 2 to 20.
Question 24
Create an array of odd numbers from 1 to 15.
Question 25
Create a countdown array from 10 down to 1 using `arange`.
Question 26
Create an array from 0 to 5 with a step of 0.5.
Question 27
Create an array of numbers from -5 to 5 using `arange`.
Question 28
Create an array of 10 numbers from 0 to 9, then reshape to 2x5.
Question 29
Use `arange` to create `[100, 90, 80, 70, 60, 50]`.
Question 30
Can `arange` be used with `dtype=float` explicitly? Provide an example.
Question 31
Generate exactly 5 equally spaced values between 0 and 1 using `linspace`.
Question 32
Generate 10 equally spaced values between 10 and 20.
Question 33
Create an array of 3 values between -1 and 1.
Question 34
Simulate time readings from 0s to 10s with exactly 11 samples.
Question 35
Create 7 evenly spaced power readings between 0 kW and 30 kW.
Question 36
Generate 100 points between 0 and 2*pi for a sine wave plot.
Question 37
Use `linspace` to generate `[10., 20., 30., 40., 50.]`.
Question 38
What happens if you omit the third parameter in `linspace(0, 1)`?
Question 39
Generate 5 values between 0 and 1, excluding the endpoint (1).
Question 40
Get both the samples and the step size using `linspace` between 0 and 10 with 5 samples.
Question 41
Convert a Python list `[5, 10, 15]` to a NumPy array using `asarray`.
Question 42
Use `asarray` to convert a tuple `(1, 2, 3)` into an array.
Question 43
What happens if you pass an existing ndarray to `asarray()`?
Question 44
Convert a nested list `[[1,2], [3,4]]` to an array using `asarray`.
Question 45
Use `asarray` to convert `[1, 2, 3]` and force `dtype=float`.
Question 46
What is the difference between `asarray()` and `asanyarray()`?
Question 47
Use `np.copy()` to make an independent copy of an array `a = np.array([1, 2])`.
Question 48
Does the assignment operator `=` create a copy of an array?
Question 49
Convert a string '123' to an array using `asarray`.
Question 50
Create a copy of an array using `np.array(arr, copy=True)`.
Question 51
Create a 3x3 identity matrix using `np.identity()`.
Question 52
Create a 4x4 identity matrix of integers using `np.identity()`.
Question 53
Create a 3x3 identity matrix using `np.eye()`.
Question 54
Create a 3x5 matrix with 1s on the main diagonal using `np.eye()`.
Question 55
Create a 4x4 matrix with 1s on the diagonal *above* the main diagonal.
Question 56
Create a 4x4 matrix with 1s on the diagonal *below* the main diagonal.
Question 57
Create a diagonal matrix from the list `[5, 10, 15]` using `np.diag()`.
Question 58
Extract the main diagonal from a matrix `[[1,2], [3,4]]`.
Question 59
Create a matrix with `[1, 2, 3]` placed on the diagonal *above* the main diagonal.
Question 60
Extract the diagonal *below* the main diagonal from a 3x3 matrix of ones.
Question 61
Use `fromfunction` to create a 1D array of length 5 where each element is its index multiplied by 3.
Question 62
Use `fromfunction` to create a 3x3 matrix where each element is the sum of its row and column indices.
Question 63
Use `fromfunction` to create a 4x4 matrix where each element is 1 if row == column else 0.
Question 64
Use `fromfunction` to create a 5x5 checkerboard pattern of 0s and 1s.
Question 65
Use `fromfunction` to create a 2x3 matrix where elements are `row_index * 10 + col_index`.
Question 66
Use `fromfunction` to create a 1D array of the first 5 squares (0, 1, 4, 9, 16).
Question 67
What data type does `np.fromfunction` pass to the function by default?
Question 68
How do you read a whitespace-separated file `data.txt` into a 1D NumPy array using `fromfile()`?
Question 69
How do you read a comma-separated file `marks.txt`?
Question 70
Read only the first 10 integers from a whitespace-separated file `nums.txt`.
Question 71
Assume `data.txt` has 20 numbers. Read them and reshape into a 4x5 matrix.
Question 72
How do you read a binary file `array.bin` containing 32-bit floats?
Question 73
What happens if you use `fromfile()` on a text file without specifying `sep`?
Question 74
Create a 2D matrix of shape 3x3 containing `i * j` using a standard python function and `fromfunction`.
Question 75
Save an array `np.arange(5)` to a binary file `out.bin`.
Question 76
Generate a single random float between 0 and 1.
Question 77
Generate an array of 10 random floats between 0 and 1.
Question 78
Generate a 2x5 matrix of random floats between 0 and 1.
Question 79
Generate a 3D array of random floats with shape (2, 3, 4).
Question 80
Generate an array of 5 random floats between 0 and 100.
Question 81
Generate an array of 5 random floats between 10 and 50.
Question 82
Generate a 3x3 matrix of random floats between 5 and 10.
Question 83
Simulate 10 student percentages (random floats between 0 and 100).
Question 84
Simulate 5 temperature readings between 20°C and 30°C.
Question 85
Convert an array of 5 random floats (0 to 100) into integers using `astype(int)`.
Question 86
Generate an array of 10 random boolean values (True or False).
Question 87
Generate an array of 10 random 0s and 1s.
Question 88
How do you ensure `np.random.rand(5)` generates the exact same numbers every time?
Question 89
What is the difference in arguments between `np.random.rand()` and `np.random.random()`?
Question 90
Generate a random array of shape (4, 4) and scale the values to be between -1 and 1.
Question 91
Simulate 5 random salaries between ₹20,000 and ₹80,000.
Question 92
Set the random seed to 100, then generate a 2x2 random matrix.
Question 93
Create a 1D array of 5 random floats, and multiply all elements by 10.
Question 94
Can `np.random.rand()` generate negative numbers natively without mathematical manipulation?
Question 95
Simulate tossing a coin 10 times (Output: array of 'Heads' or 'Tails').
Question 96
Generate a 5x2 matrix of random numbers from 0 to 1.
Question 97
Generate 10 random numbers between 0 and 1, and count how many are > 0.8.
Question 98
Generate 10 random numbers. If a number is > 0.5, replace it with 1, else 0.
Question 99
Generate a 2x2 random array. Try generating another 2x2. Are they same? How to make them same?
Question 100
Generate a random probability array of length 5 (values sum to 1).