Array creation Flashcards
How do you create an array filled with zeros?
Use np.zeros((rows, columns)), where (rows, columns) is a tuple defining the shape of the array. For example, np.zeros((3, 4)) creates a 3x4 array filled with zeros.
What does ndarray.ndim represent?
It represents the number of axes (dimensions) of the array.
What is the difference between np.arange() and np.linspace()?
np.arange(start, stop, step) generates values from start to stop with a specified step size. In contrast, np.linspace(start, stop, num) generates num evenly spaced values between start and stop.
What data types can be specified when creating an array?
You can use standard Python types (like int and float) or NumPy-specific types (like numpy.int32, numpy.float64).
How do you calculate sine values for a range of angles?
Use np.sin(array_of_angles), where array_of_angles is a NumPy array of angles in radians. For example, np.sin(np.linspace(0, np.pi, 5)) computes the sine values for 5 angles evenly spaced between 0 and
𝜋
What is the main object in NumPy?
The main object is the ndarray, a homogeneous multidimensional array.