小编kgu*_*lly的帖子

在keras中将输入与常量向量连接起来

我试图将我的输入与 keras-2 函数 API 中的常量张量连接起来。在我的实际问题中,常量取决于设置中的某些参数,但我认为下面的示例显示了我得到的错误。

from keras.layers import*
from keras.models import *
from keras import backend as K
import numpy as np

a = Input(shape=(10, 5))
a1 = Input(tensor=K.variable(np.ones((10, 5))))
x = [a, a1]  # x = [a, a] works fine
b = concatenate(x, 1)
x += [b]  # This changes b._keras_history[0].input
b = concatenate(x, 1)
model = Model(a, b)
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

ValueError                                Traceback (most recent call last)
~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/engine/topology.py in assert_input_compatibility(self, inputs)
    418             try:
--> 419                 K.is_keras_tensor(x)
    420             except ValueError:

~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/backend/theano_backend.py …
Run Code Online (Sandbox Code Playgroud)

python keras keras-2

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

无法使用tensorflow和pytorch创建conda环境

我正在尝试创建一个包含tensorflow和pytorch的conda环境。作为一个最小的例子,我正在运行

conda env create -n test -f test-env.yaml

使用以下test-env.yaml文件:

channels:
- conda-forge
- defaults
- pyviz

dependencies:
- python>=3.7,<3.8
- tensorflow>=2.0.0,<2.4.0
- pytorch>=1.0.0,<2.0.0
name: my_environment
Run Code Online (Sandbox Code Playgroud)

我收到以下长错误抱怨冲突:

$ conda env create -n test -f test-env.yaml
Collecting package metadata (repodata.json): done
Solving environment: -
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed
Solving environment: \
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed

UnsatisfiableError: …
Run Code Online (Sandbox Code Playgroud)

python conda tensorflow pytorch

5
推荐指数
0
解决办法
2862
查看次数

如何阅读IRAF多谱图光谱?

我在Iraf生成的拟合文件中有一个光谱.波长轴在标题中编码为:

WAT0_001= 'system=multispec'
WAT1_001= 'wtype=multispec label=Wavelength units=angstroms'
WAT2_001= 'wtype=multispec spec1 = "1 1 2 1. 2.1919422441886 4200 0. 452.53 471'
WAT3_001= 'wtype=linear'
WAT2_002= '.60 1. 0. 3 3 1. 4200.00000000001 1313.88904209266 1365.65012876239 '
WAT2_003= '1422.67911152069 1479.0560707956 1535.24082980747 1584.94609332243'
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法将其加载到python中?

python spectrum astropy

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

python'in'运算符返回错误的值

我在python的'in'运算符中遇到了一个奇怪的问题,它从下面的ipython shell中重现:

    In [119]: Teff = 10000

    In [120]: loggs = numpy.arange(4.5, 4*numpy.log10(Teff) - 15.02, -0.1)

    In [121]: 4.0 in loggs
    Out[121]: False

    In [122]: loggs
    Out[122]: 
    array([ 4.5,  4.4,  4.3,  4.2,  4.1,  4. ,  3.9,  3.8,  3.7,  3.6,  3.5,
    3.4,  3.3,  3.2,  3.1,  3. ,  2.9,  2.8,  2.7,  2.6,  2.5,  2.4,
    2.3,  2.2,  2.1,  2. ,  1.9,  1.8,  1.7,  1.6,  1.5,  1.4,  1.3,
    1.2,  1.1,  1. ])
Run Code Online (Sandbox Code Playgroud)

如您所见,4.0在数组中,但'in'运算符返回False.我用'4'(整数)和'4'尝试了同样的事情,两者都有相同的结果.与该数组中的其他值相同(如3.9).有任何想法吗?我正在运行python 2.7.1,numpy版本1.7.0.

我看到以前的帖子很接近,但是对于'in'发生的事情,从来没有一个好的答案.

python

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

意外的python函数返回行为

我的工作,通常1个返回值的函数,但有时出于类似的原因,以返回2 这个帖子,并注意到了这个例子最好地说明了一些意外的行为:

def testfcn1(return_two=False):
    a = 10
    return a, a*2 if return_two else a

def testfcn2(return_two=False):
    a = 10
    if return_two:
        return a, a*2
    return a
Run Code Online (Sandbox Code Playgroud)

我希望这两个函数的行为方式相同.testfcn2按预期工作:

testfcn2(False)
10

testfcn2(True)
(10, 20)
Run Code Online (Sandbox Code Playgroud)

但是,testfcn1总是返回两个值,如果return_two为False,则只返回第一个值两次:

testfcn1(False)
(10, 10)

testfcn1(True)
(10, 20)
Run Code Online (Sandbox Code Playgroud)

这种行为有理由吗?

python function

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

标签 统计

python ×5

astropy ×1

conda ×1

function ×1

keras ×1

keras-2 ×1

pytorch ×1

spectrum ×1

tensorflow ×1