# Measure a certain computational base like |0\> or |1\>?

**URL:** <https://discourse.julialang.org/t/measure-a-certain-computational-base-like-0-or-1/119650>\
**Category:** Quantum\
**Tags:** question\
**Created:** [September 20, 2024, 4:57pm UTC](https://discourse.julialang.org/t/measure-a-certain-computational-base-like-0-or-1/119650 "2024-09-20T16:57:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yao\_novice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yao_novice/32/212085_2.png) [@yao\_novice](https://discourse.julialang.org/u/yao_novice)\
**Post date:** [September 20, 2024, 4:57pm UTC](https://discourse.julialang.org/t/measure-a-certain-computational-base-like-0-or-1/119650/1 "2024-09-20T16:57:36Z")

</div>

Simple qubit state: 1/5\*[3, 4i]  
measurement against |0\> should result in 0.36 against |1\> → 0.64

```julia
import Yao

reg = Yao.ArrayReg([3.0, 4.0im]) # a unnormalized state 
Yao.normalize!(reg)
shots = 10000
m=Yao.measure(Yao.ComputationalBasis(), reg; nshots=shots)
global s=0
for i in 1:shots
    global s = s + m[i].buf
end
s/shots

```

result: 0.6306 → this is OK for measurement against |1\>  
Where is the result for |0\>?

I know a simple question but I stuck with it!

---

<div class="post-metadata">

**Author:** ![1115](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1115/32/4465_2.png) [@1115](https://discourse.julialang.org/u/1115)\
**Post date:** [September 20, 2024, 7:05pm UTC](https://discourse.julialang.org/t/measure-a-certain-computational-base-like-0-or-1/119650/2 "2024-09-20T19:05:25Z")

</div>

The way you interpreting the measurement result is not correct.

```julia
julia> m=Yao.measure(Yao.ComputationalBasis(), reg; nshots=shots)
10000-element Vector{DitStr{2, 1, Int64}}:
 1 ₍₂₎
 0 ₍₂₎
 1 ₍₂₎
 1 ₍₂₎
 1 ₍₂₎
 1 ₍₂₎
 1 ₍₂₎
 0 ₍₂₎
     ⋮
 0 ₍₂₎
 1 ₍₂₎
 0 ₍₂₎
 0 ₍₂₎
 1 ₍₂₎
 1 ₍₂₎
 0 ₍₂₎
 1 ₍₂₎

```

All the items with `0 ₍₂₎` are the result for |0\>. `buf` is the integer representation of bit strings. For example, with two qubits you will have

```julia
julia> reg = ghz_state(2)
ArrayReg{2, ComplexF64, Array...}
    active qubits: 2/2
    nlevel: 2

julia> m=Yao.measure(Yao.ComputationalBasis(), reg; nshots=shots)
10000-element Vector{DitStr{2, 2, Int64}}:
 00 ₍₂₎
 00 ₍₂₎
 11 ₍₂₎
 11 ₍₂₎
 11 ₍₂₎
 11 ₍₂₎
 00 ₍₂₎
 00 ₍₂₎
      ⋮
 00 ₍₂₎
 11 ₍₂₎
 11 ₍₂₎

```

---

<div class="post-metadata">

**Author:** ![yao\_novice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yao_novice/32/212085_2.png) [@yao\_novice](https://discourse.julialang.org/u/yao_novice)\
**Post date:** [September 20, 2024, 7:31pm UTC](https://discourse.julialang.org/t/measure-a-certain-computational-base-like-0-or-1/119650/3 "2024-09-20T19:31:56Z")

</div>

Thank you for my changing the view to the result
