小编Dom*_*rro的帖子

将数组作为参数传递时,调节内存的最有效方法是什么?

我学会了用 Python 编程,现在刚刚学习 C++,所以如果我使用的术语不是传统的(也没有comp. sci. 教育或背景),我深表歉意。

我正在尝试用 C++ 构建一个神经元。权重通常作为数组传递。在实例化神经元时,我需要传递一组权重。我一直试图让神经元对象只引用指针,这样我就不必复制,但我一直做错事。有人可以更改此代码,这样我就不会复制数组,然后解释您做了什么,为什么要这样做?

class Neuron {
    private:
        double bias;
        int num_weights;
        double weights[];
    public:
        Neuron(double*, int, double);
        double forward_prop(double[]);
};

Neuron::Neuron(double weights[], int num_weights, double bias) {
    this->num_weights = num_weights;
    this->bias = bias;
    // rotate through weights pointer and reassign to object attribute 'weights'
    for (int i=0;i<this->num_weights;i++) {
        this->weights[i] = weights[i];
    }
    // TODO: delete pointer

}

double Neuron::forward_prop(double values[]) {
    double output = this->bias;

    for (int i=0; i < this->num_weights; i++) {
        output …
Run Code Online (Sandbox Code Playgroud)

c++ arrays pointers instantiation neural-network

1
推荐指数
1
解决办法
75
查看次数

sqlite3 插入的不完整输入错误

python 新手,正在练习一个小项目。我正在尝试将用户提供的数据(名字、姓氏、性别、年龄)或生成的数据(用户 ID、数学分数、口头分数)插入到 .db 文件中。一切运行顺利,直到实际插入,它给我“sqlite3.OperationalError:不完整的输入”。我的代码中是否有错误,还是应该使用不同的策略来保存这些?我还需要稍后回忆它们以获得基本的登录页面,所以请记住这一点。

class diag:
    quantitative_diagnostic = quantitative_diagnostic_percentage
    verbal_diagnostic = verbal_diagnostic_percentage

class user:
def __init__(self):
    user_ID
    forename
    surname
    sex
    age
    quantitative_diagnostic_percentage
    verbal_diagnostic_percentage

# user info storage
conn = sqlite3.connect('promethean_user.db')
c = conn.cursor()
c.execute("INSERT INTO promethean_user VALUES (:user_ID0, :forename, 
:surname, :age, :sex, :quant_diag, :verbal_diag",
      {'user_ID0': user.user_ID,
       'forename': user.forename,
       'surname': user.surname,
       'age': user.age,
       'sex': user.sex,
       'quant_diag': diag.quantitative_diagnostic,
       'verbal_diag': diag.verbal_diagnostic})
Run Code Online (Sandbox Code Playgroud)

预期将数据保存到 .db 文件,给出错误警告“qlite3.OperationalError:输入不完整”。错误警告位于“verbal_diag”:代码的 diag.verbal_diagnostic 部分

python sql sqlite input

0
推荐指数
1
解决办法
2796
查看次数

标签 统计

arrays ×1

c++ ×1

input ×1

instantiation ×1

neural-network ×1

pointers ×1

python ×1

sql ×1

sqlite ×1