---
title: apply_unitary (latest version)
description: API reference for qiskit_fermions.linalg.apply_unitary in the latest version of qiskit-fermions
source: https://quantum.cloud.ibm.com/docs/en/api/qiskit-fermions/linalg-apply-unitary
---

# apply\_unitary

`apply_unitary(vec, operator, norb, nelec, copy=True)`

Applies a unitary transformation to a state vector.

This is a thin, type-agnostic wrapper around the [`SupportsApplyUnitary`](/docs/api/qiskit-fermions/protocols-supports-apply-unitary "qiskit_fermions.protocols.SupportsApplyUnitary") protocol method, mirroring the free-function style of [`ffsim.apply_unitary()`](https://qiskit-community.github.io/ffsim/api/stubs/ffsim.apply_unitary.html#ffsim.apply_unitary "(in ffsim)").

**Parameters**

- **vec** ([*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)) – the state vector to apply the unitary transformation to.
- **operator** ([*SupportsApplyUnitary*](/docs/api/qiskit-fermions/protocols-supports-apply-unitary "qiskit_fermions.protocols.apply_unitary.SupportsApplyUnitary")) – the object with a unitary effect, implementing [`SupportsApplyUnitary`](/docs/api/qiskit-fermions/protocols-supports-apply-unitary "qiskit_fermions.protocols.SupportsApplyUnitary").
- **norb** ([*int*](https://docs.python.org/3/library/functions.html#int)) – the number of spatial orbitals.
- **nelec** ([*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)*,* [*int*](https://docs.python.org/3/library/functions.html#int)*]*) – the electron count – an integer for a spinless sector, or an `(n_alpha, n_beta)` pair for a spinful one.
- **copy** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – whether to copy the vector before operating on it.

**Returns**

The transformed vector.

**Return type**

[*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)
