背面列出错误

背面列出错误

我已将以下代码复制到源文件中。代码未按正确格式显示(原样)。所有文本混杂(没有任何间隙)。底部没有标题。收到错误消息“环境 1stlisting 未定义”。请指导我如何更正它?我正在两行之间添加列表。

Used variable (n,m) are critical and are used by anothere functionas described in below listing. 
\begin{lstlisting}[language=Python, caption=Python example]
import numpy as np
    
def incmatrix(genl1,genl2):
    m = len(genl1)
    n = len(genl2)
    M = None #to become the incidence matrix
    VT = np.zeros((n*m,1), int) dummy variable
     compute the bitwise xor matrix
    M1 = bitxormatrix(genl1)
    M2 = np.triu(bitxormatrix(genl2),1) 

    for i in range(m-1):
        for j in range(i+1, m):
            [r,c] = np.where(M2 == M1[i,j])
            for k in range(len(r)):
                VT[(i)*n + r[k]] = 1;
                VT[(i)*n + c[k]] = 1;
                VT[(j)*n + r[k]] = 1;
                VT[(j)*n + c[k]] = 1;
                
                if M is None:
                    M = np.copy(VT)
                else:
                    M = np.concatenate((M, VT), 1)
                
                VT = np.zeros((n*m,1), int)
    
    return M
\end{lstlisting}

Now VT value is assigned to fictorial function for mathematical calculations.

文本显示为

使用的变量(n,m)至关重要,并由另一个函数使用,如下表所示。language=Python, caption=Python example] import numpy as np def incmatrix(genl1,genl2): m = len(genl1) n = len(genl2) M = None # 成为关联矩阵 VT = np.zeros((n*m,1), int) 虚拟变量计算按位异或矩阵 M1 = bitxormatrix(genl1)M2 = np.triu(bitxormatrix(genl2),1) for i in range(m-1):for j in range(i+1, m): [r,c] = np.where(M2 == M1[i,j]) for k in range(len(r)): VT[(i)*n + r[k]] = 1; VT[(i)*n + c[k]] = 1; VT[(j)*n + r[k]] = 1;VT[(j)n + c[k]] = 1; 如果 M 为 None:M = np.copy(VT),否则:M = np.concatenate((M, VT), 1)VT = np.zeros((nm,1),int)返回M。现在VT值被分配给虚构函数进行数学计算。

答案1

您没有提供显示错误的测试文档。lslisting所显示的内容不会产生所述错误,并产生此输出

在此处输入图片描述

\documentclass{article}

\usepackage{listings}

\begin{document}
\begin{lstlisting}[language=Python, caption=Python example]
import numpy as np
    
def incmatrix(genl1,genl2):
    m = len(genl1)
    n = len(genl2)
    M = None #to become the incidence matrix
    VT = np.zeros((n*m,1), int) dummy variable
     compute the bitwise xor matrix
    M1 = bitxormatrix(genl1)
    M2 = np.triu(bitxormatrix(genl2),1) 

    for i in range(m-1):
        for j in range(i+1, m):
            [r,c] = np.where(M2 == M1[i,j])
            for k in range(len(r)):
                VT[(i)*n + r[k]] = 1;
                VT[(i)*n + c[k]] = 1;
                VT[(j)*n + r[k]] = 1;
                VT[(j)*n + c[k]] = 1;
                
                if M is None:
                    M = np.copy(VT)
                else:
                    M = np.concatenate((M, VT), 1)
                
                VT = np.zeros((n*m,1), int)
    
    return M
\end{lstlisting}
\end{document}

相关内容