What are the main attributes of a NumPy ndarray (e.g., shape, ndim, size, dtype)?

Quick Overview

Explain the main attributes of a NumPy ndarray, including shape, ndim, size and dtype, and what each one says about the array. It tests whether you understand how NumPy describes layout, element type and memory use through metadata such as itemsize, nbytes and strides.

What are the main attributes of a NumPy ndarray (e.g., shape, ndim, size, dtype)?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What are the main attributes of a NumPy `ndarray` (for example `shape`, `ndim`, `size`, `dtype`)? Explain what each one tells you about the array. ```hint Group them Sort the attributes into two groups: the ones that describe the logical layout (how many axes, how long each one is) and the ones that describe the elements and the bytes in memory. ``` ### What a Strong Answer Covers - Defines `shape`, `ndim` and `size` and how they relate to each other. - Explains `dtype` and the fact that every element of the array has the same type. - Covers the memory attributes (`itemsize`, `nbytes`, `strides`) and what they reveal about layout. - Notes that these attributes are metadata, so reading them copies no data, and connects strides to how views work. ### Follow-up Questions - How do the strides change when you transpose an array or take every other column, and why is no data copied? - What is the difference between `arr.size` and `len(arr)` for a 2D array? - When does `reshape` return a view, and when does it have to copy? - What `dtype` do you get when you build an array from a mix of integers and floats, or integers and strings?

Overview: Explain the main attributes of a NumPy ndarray, including shape, ndim, size and dtype, and what each one says about the array. It tests whether you understand how NumPy describes layout, element type and memory use through metadata such as itemsize, nbytes and strides.

PracHub logo
General
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What are the main attributes of a NumPy ndarray (for example shape, ndim, size, dtype)? Explain what each one tells you about the array.

What a Strong Answer Covers Guidance

  • Defines shape , ndim and size and how they relate to each other.
  • Explains dtype and the fact that every element of the array has the same type.
  • Covers the memory attributes ( itemsize , nbytes , strides ) and what they reveal about layout.
  • Notes that these attributes are metadata, so reading them copies no data, and connects strides to how views work.

Follow-up Questions Guidance

  • How do the strides change when you transpose an array or take every other column, and why is no data copied?
  • What is the difference between arr.size and len(arr) for a 2D array?
  • When does reshape return a view, and when does it have to copy?
  • What dtype do you get when you build an array from a mix of integers and floats, or integers and strings?