遍历命令中的字符串

问题描述

我有如下代码:

n = 2
disc_weights = np.random.uniform(0,2 * np.pi,4*n)

phi =     (disc_weights[0] * QubitOperator('X0') + 
           disc_weights[1] * QubitOperator('Y0') +
           disc_weights[2] * QubitOperator('Z0') +
           disc_weights[3] * QubitOperator('X1') +
           disc_weights[4] * QubitOperator('Y1') +
           disc_weights[5] * QubitOperator('Z1') + 
           disc_weights[6] * QubitOperator('')   + 
           disc_weights[7] * QubitOperator('')   )

其中QubitOperator是我使用的软件包中的命令。如何自动执行此操作以遍历X,Y,Z,1、2 ... n并创建phi?

这可以解决问题,但还不能解决问题

phi=  functools.reduce(operator.add,(1 * QubitOperator(f'{a}{n}') for  a,n in itertools.product(["X","Y","Z"],range(n))))

解决方法

let results1 = db.Employees.find({"$text":{"$search":"senior"}},{"score":{"$meta":"textScore"}})
let results2 = db.Employees.find({"$text":{"$search":"manager"}},{"score":{"$meta":"textScore"}})
let combinedResults = _.intersectionWith(results1,results2,_.isEqual)
let finalResults = /* pass combinedResults into aggregation pipeline and execute it */

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...