---
title: BitArray (latest version)
description: API reference for qiskit.primitives.BitArray in the latest version of qiskit
source: https://quantum.cloud.ibm.com/docs/en/api/qiskit/qiskit.primitives.BitArray
---

# BitArray

*class* `qiskit.primitives.BitArray(array, num_bits)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L57-L785)

Bases: `ShapedMixin`

Stores an array of bit values.

This object contains a single, contiguous block of data that represents an array of bitstrings. The last axis is over packed bits, the second last axis is over shots, and the preceding axes correspond to the shape of the pub that was executed to sample these bits.

You typically get this object back as one part of a [`DataBin`](/docs/api/qiskit/qiskit.primitives.DataBin "qiskit.primitives.DataBin") accessed through a single [`PubResult.data`](/docs/api/qiskit/qiskit.primitives.PubResult#data "qiskit.primitives.PubResult.data"). Users do not typically create this class themselves, however if you have bitstring-like data in an alternate form that you would like to convert to a [`BitArray`](#qiskit.primitives.BitArray "qiskit.primitives.BitArray"), you can use one of [`from_bool_array()`](#qiskit.primitives.BitArray.from_bool_array "qiskit.primitives.BitArray.from_bool_array"), [`from_counts()`](#qiskit.primitives.BitArray.from_counts "qiskit.primitives.BitArray.from_counts") or [`from_samples()`](#qiskit.primitives.BitArray.from_samples "qiskit.primitives.BitArray.from_samples").

You can “unpack” the bitstrings into expanded array of [`bool`](https://docs.python.org/3/library/functions.html#bool) by using the [`to_bool_array()`](#qiskit.primitives.BitArray.to_bool_array "qiskit.primitives.BitArray.to_bool_array") method.

This class supports the bitwise `&` (and), `|` (or), `^` (xor) and `~` (not) operators, where the binary operators act on two [`BitArray`](#qiskit.primitives.BitArray "qiskit.primitives.BitArray") instances.

The class also supports the “indexing” syntax `bit_array[indices]`. These `indices` select a single entry, or multi-dimensional slice of entries, from the same shape as the corresponding pub. The allowed indices match [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray): you can use single integers, slices (`a:b`) or Numpy arrays for each dimension, and use a tuple of items to slice multiple dimensions at once. The indexing syntax cannot be used to slice along the “shots” or “bits” axes; for these, use [`slice_shots()`](#qiskit.primitives.BitArray.slice_shots "qiskit.primitives.BitArray.slice_shots") and [`slice_bits()`](#qiskit.primitives.BitArray.slice_bits "qiskit.primitives.BitArray.slice_bits"), respectively.

**Parameters**

- **array** (*NDArray\[np.uint8]*) – The `uint8` data array.
- **num\_bits** ([*int*](https://docs.python.org/3/library/functions.html#int)) – How many bits are in each outcome.

**Raises**

- [**TypeError**](https://docs.python.org/3/library/exceptions.html#TypeError) – If the input is not a NumPy array with type `numpy.uint8`.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the input array has fewer than two axes, or the size of the last axis is not the smallest number of bytes that can contain `num_bits`.

## Attributes

### array

The raw NumPy array of data.

### ndim

### num\_bits

The number of bits in the register that this array stores data for.

For example, a `ClassicalRegister(5, "meas")` would result in `num_bits=5`.

### num\_shots

The number of shots sampled from the register in each configuration.

More precisely, the length of the second last axis of [`array`](#qiskit.primitives.BitArray.array "qiskit.primitives.BitArray.array").

### shape

### size

## Methods

### bitcount

`bitcount()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L201-L211)

Compute the number of ones appearing in the binary representation of each shot.

**Returns**

A `numpy.uint64`-array with shape `(*shape, num_shots)`.

**Return type**

*NDArray*\[*uint64*]

### concatenate

*static* `concatenate(bit_arrays, axis=0)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L657-L706)

Join a sequence of bit arrays along an existing axis.

**Parameters**

- **bit\_arrays** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")*]*) – The bit arrays must have (1) the same number of bits, (2) the same number of shots, and (3) the same shape, except in the dimension corresponding to axis (the first, by default).
- **axis** ([*int*](https://docs.python.org/3/library/functions.html#int)) – The axis along which the arrays will be joined. Default is 0.

**Returns**

The concatenated bit array.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the sequence of bit arrays is empty.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If any bit arrays has a different number of bits.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If any bit arrays has a different number of shots.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If any bit arrays has a different number of dimensions.

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### concatenate\_bits

*static* `concatenate_bits(bit_arrays)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L744-L785)

Join a sequence of bit arrays along the bits axis.

> **Note**
>
> This method is equivalent to per-shot bitstring concatenation.

**Parameters**

**bit\_arrays** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")*]*) – Bit arrays that have (1) the same number of shots, and (2) the same shape.

**Returns**

The stacked bit array.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the sequence of bit arrays is empty.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If any bit arrays has a different number of shots.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If any bit arrays has a different shape.

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### concatenate\_shots

*static* `concatenate_shots(bit_arrays)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L708-L742)

Join a sequence of bit arrays along the shots axis.

**Parameters**

**bit\_arrays** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")*]*) – The bit arrays must have (1) the same number of bits, and (2) the same shape.

**Returns**

The stacked bit array.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the sequence of bit arrays is empty.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If any bit arrays has a different number of bits.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If any bit arrays has a different shape.

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### expectation\_values

`expectation_values(observables)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L613-L655)

Compute the expectation values of the provided observables, broadcasted against this bit array.

> **Note**
>
> This method returns the real part of the expectation value even if the operator has complex coefficients due to the specification of [`sampled_expectation_value()`](/docs/api/qiskit/result#qiskit.result.sampled_expectation_value "qiskit.result.sampled_expectation_value").

**Parameters**

**observables** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*Pauli*](/docs/api/qiskit/qiskit.quantum_info.Pauli "qiskit.quantum_info.operators.symplectic.pauli.Pauli")  *|*[*SparsePauliOp*](/docs/api/qiskit/qiskit.quantum_info.SparsePauliOp "qiskit.quantum_info.operators.symplectic.sparse_pauli_op.SparsePauliOp")  *|*[*SparseObservable*](/docs/api/qiskit/qiskit.quantum_info.SparseObservable "qiskit.quantum_info.SparseObservable")  *|*[*Mapping*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*Pauli*](/docs/api/qiskit/qiskit.quantum_info.Pauli "qiskit.quantum_info.operators.symplectic.pauli.Pauli")*,* [*float*](https://docs.python.org/3/library/functions.html#float)*] | ArrayLike*) – The observable(s) to take the expectation value of. Must have a shape broadcastable with this bit array and the same number of qubits as the number of bits of this bit array. The observables must be diagonal (I, Z, 0 or 1) too.

**Returns**

An array of expectation values whose shape is the broadcast shape of `observables` and this bit array.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the provided observables does not have a shape broadcastable with this bit array.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the provided observables does not have the same number of qubits as the number of bits of this bit array.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the provided observables are not diagonal.

**Return type**

*NDArray*\[*float64*]

### from\_bool\_array

*static* `from_bool_array(array, order='big')`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L213-L247)

Construct a new bit array from an array of bools.

**Parameters**

- **array** (*NDArray\[*[*bool*](https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bool)*]*) – The array to convert, with “bitstrings” along the last axis.
- **order** ([*Literal*](https://docs.python.org/3/library/typing.html#typing.Literal)*\['big', 'little']*) – One of `"big"` or `"little"`, indicating whether `array[..., 0]` correspond to the most significant bits or the least significant bits of each bitstring, respectively.

**Returns**

A new bit array.

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### from\_counts

*static* `from_counts(counts, num_bits=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L249-L290)

Construct a new bit array from one or more `Counts`-like objects.

The `counts` can have keys that are (uniformly) integers, hexstrings, or bitstrings. Their values represent numbers of occurrences of that value.

**Parameters**

- **counts** ([*Mapping*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*,* [*int*](https://docs.python.org/3/library/functions.html#int)*] |* [*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)*\[*[*Mapping*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*,* [*int*](https://docs.python.org/3/library/functions.html#int)*]]*) – One or more counts-like mappings with the same number of shots.
- **num\_bits** ([*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The desired number of bits per shot. If unset, the biggest value found sets this value, with a minimum of one bit.

**Returns**

A new bit array with shape `()` for single input counts, or `(N,)` for an iterable of $N$ counts.

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If different mappings have different numbers of shots.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If no counts dictionaries are supplied.

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### from\_samples

*static* `from_samples(samples, num_bits=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L292-L336)

Construct a new bit array from an iterable of bitstrings, hexstrings, or integers.

All samples are assumed to be integers if the first one is. Strings are all assumed to be bitstrings whenever the first string doesn’t start with `"0x"`.

Consider pairing this method with [`reshape()`](#qiskit.primitives.BitArray.reshape "qiskit.primitives.BitArray.reshape") if your samples represent nested data.

**Parameters**

- **samples** ([*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)*] |* [*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – A list of bitstrings, a list of integers, or a list of hexstrings.
- **num\_bits** ([*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The desired number of bits per sample. If unset, the biggest sample provided is used to determine this value, with a minimum of one bit.

**Returns**

A new bit array.

**Raises**

[**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If no strings are given.

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### get\_bitstrings

`get_bitstrings(loc=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L389-L402)

Return a list of bitstrings.

**Parameters**

**loc** ([*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*, ...] | None*) – Which entry of this array to return a dictionary for. If `None`, counts from all positions in this array are unioned together.

**Returns**

A list of bitstrings.

**Return type**

[list](https://docs.python.org/3/library/stdtypes.html#list)\[[str](https://docs.python.org/3/library/stdtypes.html#str)]

### get\_counts

`get_counts(loc=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L361-L373)

Return a counts dictionary with bitstring keys.

**Parameters**

**loc** ([*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*, ...] | None*) – Which entry of this array to return a dictionary for. If `None`, counts from all positions in this array are unioned together.

**Returns**

A dictionary mapping bitstrings to the number of occurrences of that bitstring.

**Return type**

[dict](https://docs.python.org/3/library/stdtypes.html#dict)\[[str](https://docs.python.org/3/library/stdtypes.html#str), [int](https://docs.python.org/3/library/functions.html#int)]

### get\_int\_counts

`get_int_counts(loc=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L375-L387)

Return a counts dictionary, where bitstrings are stored as `int`s.

**Parameters**

**loc** ([*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*, ...] | None*) – Which entry of this array to return a dictionary for. If `None`, counts from all positions in this array are unioned together.

**Returns**

A dictionary mapping `ints` to the number of occurrences of that `int`.

**Return type**

[dict](https://docs.python.org/3/library/stdtypes.html#dict)\[[int](https://docs.python.org/3/library/functions.html#int), [int](https://docs.python.org/3/library/functions.html#int)]

### postselect

`postselect(indices, selection)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L522-L611)

Post-select this bit array based on sliced equality with a given bitstring.

> **Note**
>
> If this bit array contains any shape axes, it is first flattened into a long list of shots before applying post-selection. This is done because [`BitArray`](#qiskit.primitives.BitArray "qiskit.primitives.BitArray") cannot handle ragged numbers of shots across axes.

**Parameters**

- **indices** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*] |* [*int*](https://docs.python.org/3/library/functions.html#int)) – A list of the indices of the cbits on which to postselect. If this bit array was produced by a sampler, then an index `i` corresponds to the [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") location `creg[i]` (as in [`slice_bits()`](#qiskit.primitives.BitArray.slice_bits "qiskit.primitives.BitArray.slice_bits")). Negative indices are allowed.
- **selection** ([*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*bool*](https://docs.python.org/3/library/functions.html#bool)  *|*[*int*](https://docs.python.org/3/library/functions.html#int)*] |* [*bool*](https://docs.python.org/3/library/functions.html#bool)  *|*[*int*](https://docs.python.org/3/library/functions.html#int)) – A list of binary values (will be cast to `bool`) of length matching `indices`, with `indices[i]` corresponding to `selection[i]`. Shots will be discarded unless all cbits specified by `indices` have the values given by `selection`.

**Returns**

A new bit array with `shape=(), num_bits=data.num_bits, num_shots<=data.num_shots`.

**Raises**

- [**IndexError**](https://docs.python.org/3/library/exceptions.html#IndexError) – If `max(indices)` is greater than or equal to [`num_bits`](#qiskit.primitives.BitArray.num_bits "qiskit.primitives.BitArray.num_bits").
- [**IndexError**](https://docs.python.org/3/library/exceptions.html#IndexError) – If `min(indices)` is less than negative [`num_bits`](#qiskit.primitives.BitArray.num_bits "qiskit.primitives.BitArray.num_bits").
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the lengths of `selection` and `indices` do not match.

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### reshape

`reshape(*shape)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L404-L430)

Return a new reshaped bit array.

The [`num_shots`](#qiskit.primitives.BitArray.num_shots "qiskit.primitives.BitArray.num_shots") axis is either included or excluded from the reshaping procedure depending on which picture the new shape is compatible with. For example, for a bit array with shape `(20, 5)` and `64` shots, a reshape to `(100,)` would leave the number of shots intact, whereas a reshape to `(200, 32)` would change the number of shots to `32`.

**Parameters**

**\*shape** ([*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*Iterable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)*\[*[*int*](https://docs.python.org/3/library/functions.html#int) *| Iterable\[ShapeInput]]*) – The new desired shape.

**Returns**

A new bit array.

**Raises**

[**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the size corresponding to your new shape is not equal to either [`size`](#qiskit.primitives.BitArray.size "qiskit.primitives.BitArray.size"), or the product of [`size`](#qiskit.primitives.BitArray.size "qiskit.primitives.BitArray.size") and [`num_shots`](#qiskit.primitives.BitArray.num_shots "qiskit.primitives.BitArray.num_shots").

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### slice\_bits

`slice_bits(indices)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L462-L497)

Return a bit array sliced along the bit axis of some indices of interest.

> **Note**
>
> The convention used by this method is that the index `0` corresponds to the least-significant bit in the [`array`](#qiskit.primitives.BitArray.array "qiskit.primitives.BitArray.array"), or equivalently the right-most bitstring entry as returned by [`get_counts()`](#qiskit.primitives.BitArray.get_counts "qiskit.primitives.BitArray.get_counts") or [`get_bitstrings()`](#qiskit.primitives.BitArray.get_bitstrings "qiskit.primitives.BitArray.get_bitstrings"), etc.
>
> If this bit array was produced by a sampler, then an index `i` corresponds to the [`ClassicalRegister`](/docs/api/qiskit/circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") location `creg[i]`.

**Parameters**

**indices** ([*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The bit positions of interest to slice along.

**Returns**

A bit array sliced along the bit axis.

**Raises**

[**IndexError**](https://docs.python.org/3/library/exceptions.html#IndexError) – If there are any invalid indices of the bit axis.

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### slice\_shots

`slice_shots(indices)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L499-L520)

Return a bit array sliced along the shots axis of some indices of interest.

**Parameters**

**indices** ([*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*Sequence*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*]*) – The shots positions of interest to slice along.

**Returns**

A bit array sliced along the shots axis.

**Raises**

[**IndexError**](https://docs.python.org/3/library/exceptions.html#IndexError) – If there are any invalid indices of the shots axis.

**Return type**

[*BitArray*](#qiskit.primitives.BitArray "qiskit.primitives.containers.bit_array.BitArray")

### to\_bool\_array

`to_bool_array(order='big')`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L338-L359)

Convert this [`BitArray`](#qiskit.primitives.BitArray "qiskit.primitives.BitArray") to a boolean array.

**Parameters**

**order** ([*Literal*](https://docs.python.org/3/library/typing.html#typing.Literal)*\['big', 'little']*) – One of `"big"` or `"little"`, respectively indicating whether the most significant bit or the least significant bit of each bitstring should be placed at `[..., 0]`.

**Returns**

A NumPy array of bools.

**Raises**

[**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the order is not one of `"big"` or `"little"`.

**Return type**

*NDArray*\[[*bool*](https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.bool)]

### transpose

`transpose(*axes)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/primitives/containers/bit_array.py#L432-L460)

Return a bit array with axes transposed.

**Parameters**

**axes** – None, tuple of ints or n ints. See [ndarray.transpose](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.transpose.html#numpy.ndarray.transpose) for the details.

**Returns**

A bit array with axes permuted.

**Return type**

[BitArray](#qiskit.primitives.BitArray "qiskit.primitives.BitArray")

**Raises**

- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If `axes` don’t match this bit array.
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If `axes` includes any indices that are out of bounds.
