标签: valueerror

Python:使用 SciPy 文档对 .csv 值执行 FFT

我想对数据系列执行快速傅里叶变换。该系列包含 407 天内一致采样的每日地震振幅值。我想在这个数据集中搜索任何周期性周期。

我在这里使用 SciPy 文档进行了初步尝试:https://docs.scipy.org/doc/scipy/reference/tutorial/fftpack.html。类似于这个问题(链接),然后我将 y 的参数从人工正弦函数更改为我的数据集。

但是,我收到以下错误:

ValueError: x and y must have same first dimension, but have shapes (203,) and (407, 1)
Run Code Online (Sandbox Code Playgroud)

我希望能帮助您理解为什么会出现此错误以及如何修复它。

我还希望获得有关 FFT 处理数据集所需的正确频率和采样输入值的帮助。我的数据集中有 407 个值,每个值代表一天。因此,我定义了 N(样本点数)= 407,T(样本间距)= 1 / 84600(1 / 一天的秒数)。那是对的吗?

这是我的完整代码:

import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import fft, ifft
import pandas as pd

# Import csv file
df = pd.read_csv('rsam_2016-17_fft_test.csv', index_col=['DateTime'], parse_dates=['DateTime'])
print(df.head())

#plot data
plt.figure(figsize=(12,4))
df.plot(linestyle = '', marker = '*', color='r') …
Run Code Online (Sandbox Code Playgroud)

python csv fft scipy valueerror

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

itertools.islice 与 functools.partial 一起使用时会引发 ValueError

考虑以下 python 会话 (3.6.1):

>>> from itertools import islice
>>> l = [i for i in range(10)]
>>> islice(l, 0, 1)
<itertools.islice object at 0x7f87c9293638>
>>> (lambda it: islice(it, 0, 1))(l)
<itertools.islice object at 0x7fe35ab40408>
Run Code Online (Sandbox Code Playgroud)

这里没有什么是意外的。现在,与functools.partial

>>> from functools import partial
>>> partial(islice, 0, 1)(l)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Stop argument for islice() must be None or an integer: 0 <= x <= sys.maxsize.
Run Code Online (Sandbox Code Playgroud)

partialislice似乎以一种非常意想不到的方式干扰行为。

这种行为背后的理由是什么?这是因为 islice 不处理关键字参数, …

python valueerror

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

PIL ValueError:图像不匹配

我一直在用 PIL 在 python 中搞乱,我正在研究一个在 4 个象限中镜像和图像的函数。显然我遇到了错误,而且我似乎无法弄清楚。我的功能如下:

def mirror_four(image):
    x = image.size[0]
    y = image.size[1]
    
    temp = Image.new("RGB", (image.size[0], image.size[1]), "black")
    
    tl = image
    tr = mirror_left(image)
    bl = mirror_verticle(image)
    br = mirror_verticle(tr)
    
    image.paste(temp,(0,0,int(x/2),int(y/2)),tl)
    image.paste(temp,(int(x/2),0,0,int(y/2)),tr)
    image.paste(temp,(0,int(y/2),int(x/2),0),bl)
    image.paste(temp,(x/2,y/2,x,y),br)
    
    return temp
Run Code Online (Sandbox Code Playgroud)

这将返回错误:ValueError:图像不匹配

我有点迷失,PIL 文档对我没有多大帮助。

python image python-imaging-library valueerror

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

如何修复 Tensorflow 中的“ValueError:操作数无法与形状 (2592,) (4,) 一起广播”?

我目前正在设计一个 NoisyNet 层,正如这里所建议的:“Noisy Networks for Exploration”,在 Tensorflow 中并获得标题中所示的维数误差,而两个张量的维数要逐元素相乘filtered_output = keras.layers.merge.Multiply()([output, actions_input])应该(在原则)在打印所涉及的两个张量的维度时,根据打印输出彼此兼容,filtered_output并且actions_input,其中两个张量似乎都是维度shape=(1, 4)

我在 Python3 中使用 Tensorflow 1.12.0。

相关代码如下所示:

import numpy as np
import tensorflow as tf
import keras

class NoisyLayer(keras.layers.Layer):

    def __init__(self, in_shape=(1,2592), out_units=256, activation=tf.identity): 
        super(NoisyLayer, self).__init__()
        self.in_shape = in_shape
        self.out_units = out_units
        self.mu_interval = 1.0/np.sqrt(float(self.out_units))
        self.sig_0 = 0.5
        self.activation = activation
        self.assign_resampling()

    def build(self, input_shape):
        # Initializer
        self.mu_initializer = tf.initializers.random_uniform(minval=-self.mu_interval, maxval=self.mu_interval) # Mu-initializer
        self.si_initializer = tf.initializers.constant(self.sig_0/np.sqrt(float(self.out_units)))      # Sigma-initializer

        # …
Run Code Online (Sandbox Code Playgroud)

python python-3.x tensorflow valueerror

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

使用 .loc 和 OR 运算符返回 ValueError

我试图在两列中的任意一列中搜索特定值,当找到目标值时,将第三列中的数字从正数更改为负数或从负数更改为正数。

te1 = df.loc[df['Transaction Event'] == 'Exercise']
te2 = df.loc[df['Transaction Event'] == 'Assignment']
te3 = df.loc[df['Transaction Event'] == 'Expiration']
an1 = df.loc[df['Action'] == 'Delete']
nq = df['Net Quantity']
var1 = df[(df['Transaction Event'] == 'Exercise') | (df['Transaction Event'] == 'Assignment') | (df['Transaction Event'] == 'Expiration') | (df['Action'] == 'Delete')]

df.loc[df[var1], nq] = df.loc[df[var1], nq] * -1
Run Code Online (Sandbox Code Playgroud)

运行此代码会返回以下错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-282-01dbb8066276> in <module>()
      6 var1 = df[(df['Transaction Event'] == 'Exercise') | (df['Transaction Event'] == 'Assignment') | (df['Transaction …
Run Code Online (Sandbox Code Playgroud)

python operators pandas valueerror

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

尝试使用 pipenv 安装时出现 ValueError

我对此完全陌生。所以我使用'pip install pipenv'安装了pipenv。我有 python 版本 3.8.2、pip 版本 20.1.1 和 pipenv 版本 2020.6.2 。但是当我尝试运行“pipenv install”时,它给出了以下错误。

    C:\Users\rd463>pipenv install
Traceback (most recent call last):
  File "D:\python382\Lib\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 618, in parse_executable
    result_version = get_python_version(path)
  File "D:\python382\Lib\site-packages\pipenv\vendor\pythonfinder\utils.py", line 105, in get_python_version
    c = subprocess.Popen(version_cmd, **subprocess_kwargs)
  File "d:\python382\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "d:\python382\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another …
Run Code Online (Sandbox Code Playgroud)

python valueerror pipenv

5
推荐指数
3
解决办法
2603
查看次数

ValueError:未知层:自定义&gt;CTCLayer。请确保将此对象传递给“custom_objects”参数

我想在另一个应用程序中使用Keras 手写识别示例中描述的训练模型,并尝试使用以下内容加载模型;

from keras.models import load_model
from tensorflow import keras

model = keras.models.load_model("test4_20211113.h5", custom_objects={'CTCLayer': CTCLayer}) 
Run Code Online (Sandbox Code Playgroud)

我收到“ValueError:未知层:Custom>CTCLayer。请确保将此对象传递给参数custom_objects。”

我添加了 custom_objects 参数,并通过在本文“ ValueError:未知层:CapsuleLayer ”之后添加 **kwargs 来修改 CTCLayer 类。

class CTCLayer(keras.layers.Layer):
    def __init__(self, name=None, **kwargs):
        self.name = name
        super().__init__(**kwargs)
        self.loss_fn = keras.backend.ctc_batch_cost

    def call(self, y_true, y_pred):
        batch_len = tf.cast(tf.shape(y_true)[0], dtype="int64")
        input_length = tf.cast(tf.shape(y_pred)[1], dtype="int64")
        label_length = tf.cast(tf.shape(y_true)[1], dtype="int64")

        input_length = input_length * \
            tf.ones(shape=(batch_len, 1), dtype="int64")
        label_length = label_length * \
            tf.ones(shape=(batch_len, 1), dtype="int64")
        loss = self.loss_fn(y_true, y_pred, input_length, label_length) …
Run Code Online (Sandbox Code Playgroud)

python custom-object keras tensorflow valueerror

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

拥抱脸 | ValueError:连接错误,我们在缓存路径中找不到请求的文件。请重试或确保您的网络连接正常

并非总是如此,但在运行我的代码时偶尔会出现此错误。

起初,我怀疑这是一个连接问题,而是与兑现问题有关,正如旧的Git Issue中所讨论的那样。

清除缓存对运行时没有帮助:

$ rm ~/.cache/huggingface/transformers/ *
Run Code Online (Sandbox Code Playgroud)

回溯参考:

  • NLTK 也得到Error loading stopwords: <urlopen error [Errno -2] Name or service not known.
  • 最后 2 行 recached_pathget_from_cache.

缓存(清除之前):

$ cd ~/.cache/huggingface/transformers/
(sdg) me@PF2DCSXD:~/.cache/huggingface/transformers$ ls
16a2f78023c8dc511294f0c97b5e10fde3ef9889ad6d11ffaa2a00714e73926e.cf2d0ecb83b6df91b3dbb53f1d1e4c311578bfd3aa0e04934215a49bf9898df0
16a2f78023c8dc511294f0c97b5e10fde3ef9889ad6d11ffaa2a00714e73926e.cf2d0ecb83b6df91b3dbb53f1d1e4c311578bfd3aa0e04934215a49bf9898df0.json
16a2f78023c8dc511294f0c97b5e10fde3ef9889ad6d11ffaa2a00714e73926e.cf2d0ecb83b6df91b3dbb53f1d1e4c311578bfd3aa0e04934215a49bf9898df0.lock
4029f7287fbd5fa400024f6bbfcfeae9c5f7906ea97afcaaa6348ab7c6a9f351.723d8eaff3b27ece543e768287eefb59290362b8ca3b1c18a759ad391dca295a.h5
4029f7287fbd5fa400024f6bbfcfeae9c5f7906ea97afcaaa6348ab7c6a9f351.723d8eaff3b27ece543e768287eefb59290362b8ca3b1c18a759ad391dca295a.h5.json
4029f7287fbd5fa400024f6bbfcfeae9c5f7906ea97afcaaa6348ab7c6a9f351.723d8eaff3b27ece543e768287eefb59290362b8ca3b1c18a759ad391dca295a.h5.lock
684fe667923972fb57f6b4dcb61a3c92763ad89882f3da5da9866baf14f2d60f.c7ed1f96aac49e745788faa77ba0a26a392643a50bb388b9c04ff469e555241f
684fe667923972fb57f6b4dcb61a3c92763ad89882f3da5da9866baf14f2d60f.c7ed1f96aac49e745788faa77ba0a26a392643a50bb388b9c04ff469e555241f.json
684fe667923972fb57f6b4dcb61a3c92763ad89882f3da5da9866baf14f2d60f.c7ed1f96aac49e745788faa77ba0a26a392643a50bb388b9c04ff469e555241f.lock
c0c761a63004025aeadd530c4c27b860ec4ecbe8a00531233de21d865a402598.5d12962c5ee615a4c803841266e9c3be9a691a924f72d395d3a6c6c81157788b
c0c761a63004025aeadd530c4c27b860ec4ecbe8a00531233de21d865a402598.5d12962c5ee615a4c803841266e9c3be9a691a924f72d395d3a6c6c81157788b.json
c0c761a63004025aeadd530c4c27b860ec4ecbe8a00531233de21d865a402598.5d12962c5ee615a4c803841266e9c3be9a691a924f72d395d3a6c6c81157788b.lock
fc674cd6907b4c9e933cb42d67662436b89fa9540a1f40d7c919d0109289ad01.7d2e0efa5ca20cef4fb199382111e9d3ad96fd77b849e1d4bed13a66e1336f51
fc674cd6907b4c9e933cb42d67662436b89fa9540a1f40d7c919d0109289ad01.7d2e0efa5ca20cef4fb199382111e9d3ad96fd77b849e1d4bed13a66e1336f51.json
fc674cd6907b4c9e933cb42d67662436b89fa9540a1f40d7c919d0109289ad01.7d2e0efa5ca20cef4fb199382111e9d3ad96fd77b849e1d4bed13a66e1336f51.lock
Run Code Online (Sandbox Code Playgroud)

代码:

from transformers import pipeline, set_seed

generator = pipeline('text-generation', model='gpt2')  # Error
set_seed(42)
Run Code Online (Sandbox Code Playgroud)

追溯:

2022-03-03 10:18:06.803989: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; …
Run Code Online (Sandbox Code Playgroud)

python-3.x tensorflow valueerror huggingface-transformers gpt-2

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

在 pandas 中处理时间序列数据时,如何解决“ValueError:无法在具有重复标签的轴上重新索引”错误?

                       cube   timestamp          temp   
timestamp               
2022-08-01 00:15:05.135  A1       2022-08-01 00:15:05.135    NaN

2022-08-01 00:15:37.255  A1       2022-08-01 00:15:37.255    23.17  

2022-08-01 00:23:05.139  A1       2022-08-01 00:23:05.139    NaN    

2022-08-01 00:23:15.137  A1       2022-08-01 00:23:15.137    NaN    

2022-08-11 11:33:20.738  P19      2022-08-11 00:15:05.135    NaN    
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用以下代码根据相对于立方体的时间戳插入温度中的 NaN 值

idata.set_index(idata['timestamp'],inplace = True)

idata['temp'] = idata.groupby('cube')['temp'].apply(lambda x:x.interpolate(method="time",limit_direction = "both"))
Run Code Online (Sandbox Code Playgroud)

执行此代码时,我收到错误“ValueError:无法在具有重复标签的轴上重新索引”。我无法删除重复的标签(时间戳),因为它可能属于不同的多维数据集。请提出处理这种情况的替代方案。

python time-series pandas valueerror

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

如何修复“ValueError:无法实例化此分词器。请确保安装了 `sentencepiece` 才能使用此分词器。”

我正在尝试在 Google Colab 中使用以下代码运行 Hugging Face 模型:

!pip install transformers

from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-es")
inputs = tokenizer(text, return_tensors="pt").input_ids
Run Code Online (Sandbox Code Playgroud)

我遇到以下错误:

ValueError: This tokenizer cannot be instantiated. Please make sure you have `sentencepiece` installed in order to use this tokenizer.
Run Code Online (Sandbox Code Playgroud)

我如何解决它?

python valueerror google-colaboratory huggingface-transformers

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