The result of qml.expval, qml.sample and qml.probs are objects of ‘ExpectationMP’ type which can not converted into np.array. FOr instance, here in "I.10 What did you expect? " of Pennylane codebook, how can I store results into numpy array;
# An array to store your results
shot_results = []
# Different numbers of shots
shot_values = [100, 1000, 10000, 100000, 1000000]
def fun(shoot):
dev = qml.device('default.qubit' , wires =1 ,shots=shoot)
qml.qnode(dev)
qml.RX(np.pi/4 , 0)
qml.Hadamard(0)
qml.PauliZ(0)
# STORE RESULT IN SHOT_RESULTS ARRAY
return qml.expval(qml.PauliY(0))
for shots in shot_values:
##################
# YOUR CODE HERE #
##################
# CREATE A DEVICE, CREATE A QNODE, AND RUN IT
for shoot in shot_values:
shot_results.append(fun(shoot)) # I got Error: 'ExpectationMP' object has no attribute 'numpy'
print(qml.math.unwrap(shot_results))