Log2 of the variables

I have two variables p_1, and p_2. Basically, they represent the channel matrix

[p_1 1 - p_1; 1 - p_2 p_2]

Now, I have followed this link to compute mutual information (https://www.cvxpy.org/examples/applications/Channel_capacity_BV4.57.html). However, whenever I try to c = np.sum(P*np.log2(P),axis=0), it shows the error ‘‘Variable’ object has no attribute ‘log2’’. My code is below:

import cvxpy as cp
import numpy as np

p1 = cp.Variable()
p2 = cp.Variable()

p0 = 0.5

P = np.array([[p1, 1- p1],
[1 - p2, p2]])

x = np.array([[p0],
[1 - p0]])

y = P * x

c = np.sum(P*np.log2( P ),axis=0)

I have two questions. 1. Why am I getting the previous error? 2. Is it possible to have optimization variable in log2 term and still solve the optimization problem using cvxpy?

This is the CVX forum. CVXPY is a different tool, and has a forum at https://groups.google.com/forum/#!forum/cvxpy

I don’t know if you are doing anything improper using numpy with CVXPY objects. Nevertheless, if log2 is not supported, you can rewrite log2(x) as log(x)/log(2).