# Expectation Value from Counts

**URL:** <https://discuss.pennylane.ai/t/expectation-value-from-counts/9429>\
**Category:** PennyLane Help\
**Created:** [August 3, 2026, 6:29pm UTC](https://discuss.pennylane.ai/t/expectation-value-from-counts/9429 "2026-08-03T18:29:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![movingwaters](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@movingwaters](https://discuss.pennylane.ai/u/movingwaters)\
**Post date:** [August 3, 2026, 6:29pm UTC](https://discuss.pennylane.ai/t/expectation-value-from-counts/9429/1 "2026-08-03T18:29:47Z")

</div>

Hello,

I am wondering if there is a way in Pennylane to calculate the expectation of an observable based on counts outside of a qnode circuit?

For example, with this circuit is there method within pennylane to easily calculate the expectation value as if we would have returned `[qp.expval(qp.PauliX(i)) for i in device.wires]` in the qnode?

```auto
device = qp.device("default.qubit", 4)

@qp.set_shots(1000)
@qp.qnode(device)
def circuit():
    qp.H(wires=[i])

    return qp.counts(wires=device.wires)

counts = circuit()

```

Thank you!

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [August 5, 2026, 10:55pm UTC](https://discuss.pennylane.ai/t/expectation-value-from-counts/9429/2 "2026-08-05T22:55:19Z")

</div>

Hi @movingwaters ,

You can return more than one measurement. In the example below the qnode returns both the counts and the expvals. I don’t think there’s an easy function to calculate the expvals directly from the counts though.

```auto
import pennylane as qp
device = qp.device("default.qubit", 4)

@qp.set_shots(1000)
@qp.qnode(device)
def circuit():
  for i in range(2):
    qp.H(wires=[i])

  return qp.counts(wires=device.wires), [qp.expval(qp.PauliX(i)) for i in device.wires]

counts, expvals = circuit()
print(expvals)

```

I hope this helps!

---

<div class="post-metadata">

**Author:** ![movingwaters](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@movingwaters](https://discuss.pennylane.ai/u/movingwaters)\
**Post date:** [August 15, 2026, 4:33pm UTC](https://discuss.pennylane.ai/t/expectation-value-from-counts/9429/3 "2026-08-15T16:33:58Z")

</div>

Okay great, thank you!
