Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Type Alias

np.bool_

np.bool_ is NumPy’s Boolean dtype and scalar type, representing True or False with byte-sized storage. Use it to declare Boolean arrays or convert array data explicitly.

How it works

np.bool_ is NumPy's Boolean scalar and dtype class. Use it when constructing Boolean arrays or converting existing data; unlike assigning a dtype attribute directly, conversion with astype expresses an intentional dtype change.

Syntax

np.bool_

Returns

A NumPy Boolean scalar or Boolean dtype when used as a dtype specification.

Key points

  • It represents Boolean values and uses byte-sized storage.
  • Import NumPy normally, then access the dtype as np.bool_.
  • NumPy numerical types are represented through dtype objects with distinct characteristics.
  • Use astype for an explicit array conversion to Boolean dtype.
  • The dtype callable can also be used to construct or convert a value.

Example: Create a Boolean array

import numpy as np

values = np.array([0, 1, 2], dtype=np.bool_)
print(values)
print(values.dtype)
print(type(values[1]))

Creates an array with NumPy's Boolean dtype and displays its values, dtype, and scalar element type.

When to use it

Boolean array construction

Define an array whose elements use NumPy Boolean storage.

Array conversion

Convert numeric or other array data into Boolean values.

Dtype specification

Specify a NumPy Boolean dtype in APIs that accept dtype objects.

Interview questions

QWhat is np.bool_?

np.bool_ is NumPy's Boolean type, representing True or False in a byte-sized NumPy dtype. It is available as a NumPy dtype and scalar type.

Follow-up: How would you convert an existing array? Use array.astype(np.bool_) when creating a converted array.

QHow does Python bool relate to np.bool_?

Python's built-in bool can be used as a dtype and NumPy maps it to np.bool_. Explicitly naming np.bool_ makes the NumPy dtype choice clear.

Follow-up: What should be inspected to determine an array's type? Check the array's dtype attribute.

QHow is np.bool_ commonly applied to arrays?

Use np.bool_ in array construction or with astype to obtain Boolean storage. NumPy dtypes are objects with their own characteristics, so the resulting array exposes that dtype through dtype.

Follow-up: What alternative does the documentation prefer for changing an array's dtype representation? Use astype rather than mutating the dtype attribute.

  • numpy.dtype
  • numpy.ndarray.astype
  • numpy.ndarray.view
  • bool

Source: Data types — NumPy v1.20 Manual. Checked 2026-10-15.