小编Kry*_*rix的帖子

NotImplementedError:无法将符号张量转换为 numpy 数组

下面的代码去年还可以使用,但 keras/tensorflow/numpy 中的更新破坏了它。它现在输出下面的异常。有谁知道如何让它再次工作?

我正在使用:

  • 张量流 2.4.1
  • 凯拉斯 2.4.3
  • Numpy 1.20.1
  • 蟒蛇 3.9.1
import numpy as np
from keras.layers import LSTM, Embedding, Input, Bidirectional

dim = 30
max_seq_length = 40
vecs = np.random.rand(45,dim)

input_layer = Input(shape=(max_seq_length,))
embedding_layer = Embedding(len(vecs), dim, weights=[vecs], input_length=max_seq_length, trainable=False, name="layerA")(input_layer)
lstm_nobi = LSTM(max_seq_length, return_sequences=True, activation="linear", name="layerB")
lstm = Bidirectional(lstm_nobi, name="layerC")(embedding_layer)
Run Code Online (Sandbox Code Playgroud)

上面脚本的完整输出:https : //pastebin.com/DsQNWVwz

缩短输出:

2021-02-10 17:51:13.037468: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-02-10 17:51:13.037899: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI …
Run Code Online (Sandbox Code Playgroud)

numpy tensorflow

7
推荐指数
2
解决办法
6362
查看次数

Rust 将闭包附加到向量

正如这篇文章所说,你可以像这样创建一个闭包向量:

let mut xs: Vec<Box<dyn Fn((i32, i32)) -> (i32, i32)>> = vec![
    Box::new(move |(x, y)| (y, x)),
    Box::new(move |(x, y)| (1 - y, 1 - x)),
];
Run Code Online (Sandbox Code Playgroud)

但是为什么不能使用以下方法附加到它:

xs.append(Box::new(move |(x, y)| (2 - y, 2 - x)));
Run Code Online (Sandbox Code Playgroud)

这引发了错误:

    |
162 |         xs.append(Box::new(move |(x, y)| (2 - y, 2 - x)));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected mutable reference, found struct `std::boxed::Box`                                                            
    |
    = note: expected mutable reference `&mut std::vec::Vec<std::boxed::Box<dyn std::ops::Fn((i32, i32)) -> (i32, i32)>>`                                      
                          found struct `std::boxed::Box<[closure@src/lib.rs:162:22: 162:50]>`
Run Code Online (Sandbox Code Playgroud)

closures types rust

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

C++ char [100] ="hello"不起作用

是否有更好,更短,更容易阅读的以下代码版本:

char ar[100];

int main() {
    //ar = "hello"; doesn't compile
    ar[0] = 'h';
    ar[1] = 'e';
    ar[2] = 'l';
    ar[3] = 'l';
    ar[4] = 'o';
    ar[5] = '\x00';
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

注意:类型ar必须是char[100]."真正的"计划是:

#include <string>
#include <cstdarg>

#define TO_STRING_BUF_SIZE 100

char toStringBuf[TO_STRING_BUF_SIZE];

std::string toCptr_(const char * format, ...) {
  va_list argzeiger;
  va_start(argzeiger, format);
  int16_t ret = vsnprintf(toStringBuf, TO_STRING_BUF_SIZE, format, argzeiger);
  if(ret >= TO_STRING_BUF_SIZE - 1) {
    //toStringBuf = "buffer too small";
  } else if(ret < 0) …
Run Code Online (Sandbox Code Playgroud)

c++

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

模块中的可变范围

长话短说:为什么该程序输出“ 0”而不是“ 5”,如何使它输出“ 5”:main.py:

from mod import *
setvar(5)
printvar()
Run Code Online (Sandbox Code Playgroud)

mod.py:

var = 0
def setvar(x):
    var = x
def printvar():
    print("var =", var)
Run Code Online (Sandbox Code Playgroud)

python variables module

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

标签 统计

c++ ×1

closures ×1

module ×1

numpy ×1

python ×1

rust ×1

tensorflow ×1

types ×1

variables ×1