Prepare Interview

Mock Exams

Make Homepage

## Intermediate / 1 to 5 years experienced level questions & answers

### Ques 1. Explain broadcasting in NumPy.

Broadcasting is a powerful mechanism that allows NumPy to work with arrays of different shapes when performing arithmetic operations.

### Ques 2. How to perform element-wise multiplication of two NumPy arrays?

import numpy as npnarr1 = np.array([1, 2, 3])narr2 = np.array([4, 5, 6])nresult = arr1 * arr2

### Ques 3. Explain the purpose of np.random.seed() in NumPy.

np.random.seed() is used to initialize the random number generator in NumPy, ensuring reproducibility of random results.

### Ques 4. Explain the concept of a NumPy universal function (ufunc).

A ufunc in NumPy is a flexible function that operates element-wise on NumPy arrays, supporting broadcasting.

### Ques 5. How to concatenate two NumPy arrays vertically?

You can use 'np.vstack()' or 'np.concatenate()' with 'axis=0'.

### Ques 6. What is the purpose of 'np.ravel()' in NumPy?

'np.ravel()' returns a flattened 1D array from a multi-dimensional array.

### Ques 7. Explain the purpose of 'np.concatenate()' in NumPy.

'np.concatenate()' joins a sequence of arrays along an existing axis.

### Ques 8. How to perform matrix multiplication in NumPy?

You can use 'np.matmul()' or the '@' operator. For example, 'result = np.matmul(arr1, arr2)' or 'result = arr1 @ arr2'.