首页 > 解决方案 > 你能在 Q# 中发送一个量子比特子数组作为参数吗?

问题描述

是否可以将量子比特的数组切片作为参数发送?像这样的东西:

using(q : Qubit[5]){
    myOp(q[2:3]);
}

标签: q#qubit

解决方案


Yes, Q# supports array slicing: https://docs.microsoft.com/en-us/quantum/quantum-qr-expressions#array-expressions. You can use Range data type as an index to create a subarray of elements of the array indexed by elements of the range.

Your example will look like this:

using (q = Qubit[5]) {
    myOp(q[2..3]);
}

推荐阅读