Zero dimensional arrays or scalars

scalar_array = np.array(“one_element”)
print(scalar_array, np.ndim(scalar_array), scalar_array.dtype)

Output

one_element 0 <U11

I did not understand the output 0 <U11?

Hi,
Can you give more context here so we can help resolve your issue? Can you mention the course name and the section, and the unit number as well?

please refer this

Let me take a look and reply back

Hi,

You can see the print statement, which is,

print(scalar_array, np.ndim(scalar_array), scalar_array.dtype)

The output is given as:
scalar_array → one_element
np.ndim(scalar_array) → 0
scalar_array.dtype → <U11

TO elaborate:
np.ndim(scalar_array) → 0

Because there are no axes (it’s not a vector or matrix, just a scalar).

Example:

np.array([1,2,3]) → ndim = 1
np.array([[1,2],[3,4]]) → ndim = 2
np.array(“one_element”) → ndim = 0

Further, scalar_array.dtype → <U11

< means little-endian byte order (not important for text usually, doesn’t really affect Unicode strings in practice — it’s more relevant for numbers).
U means Unicode string.
11 means each string element has max length 11 characters.
“one_element” has 11 characters, so dtype = <U11.

Hope this helps.