Python &引用;浮动;对象不可复制错误;但我不明白我';我在重复?
我正在尝试将fast5(HDF5)数据文件重写为abf格式,我有以下代码可以将给定的fast5文件重写为通用数据类型,以便使用其他工具重写为abf。但是,下面的代码在数字化步骤中会产生错误Python &引用;浮动;对象不可复制错误;但我不明白我';我在重复?,python,Python,我正在尝试将fast5(HDF5)数据文件重写为abf格式,我有以下代码可以将给定的fast5文件重写为通用数据类型,以便使用其他工具重写为abf。但是,下面的代码在数字化步骤中会产生错误 from uuid import uuid4 import numpy as np from fast5_research import BulkFast5 filename='test1.fast5' mean, stdv, n = 40.0, 2.0, 10000 raw_data = np.rando
from uuid import uuid4
import numpy as np
from fast5_research import BulkFast5
filename='test1.fast5'
mean, stdv, n = 40.0, 2.0, 10000
raw_data = np.random.laplace(mean, stdv/np.sqrt(2))
# example of how to digitize data
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
rng = stop - start
digitisation = 8192.0
bins = np.arange(start, stop, rng / digitisation)
# np.int16 is required, the library will refuse to write anything other
raw_data = np.digitize(raw_data, bins).astype(np.int16)
# The following are required meta data
channel_id = {
'digitisation': digitisation,
'offset': 0,
'range': rng,
'sampling_rate': 4000,
'channel_number': 1,
}
read_id = {
'start_time': 0,
'duration': len(raw_data),
'read_number': 1,
'start_mux': 1,
'read_id': str(uuid4()),
'scaling_used': 1,
'median_before': 0,
}
tracking_id = {
'exp_start_time': '1970-01-01T00:00:00Z',
'run_id': str(uuid4()).replace('-',''),
'flow_cell_id': 'FAH00000',
}
context_tags = {}
with Fast5.New(filename, 'w', tracking_id=tracking_id, context_tags=context_tags, channel_id=channel_id) as h:
h.set_raw(raw_data, meta=read_id, read_number=1)
错误地
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import fnmatch, glob, traceback, errno, sys, atexit, locale, imp, stat
Traceback (most recent call last):
File "/home/archie/PycharmProjects/Fast5read/Fast5rewrite.py", line 11, in <module>
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
TypeError: 'float' object is not iterable
/usr/lib/python3/dist-packages/apport/report.py:13:DeprecationWarning:imp模块被弃用,取而代之的是importlib;有关替代用途,请参阅模块文档
导入fnmatch、glob、traceback、errno、sys、atexit、locale、imp、stat
回溯(最近一次呼叫最后一次):
文件“/home/archie/PycharmProjects/Fast5read/Fast5rewrite.py”,第11行,在
开始,停止=int(最小值(原始数据-1)),int(最大值(原始数据+1))
TypeError:“float”对象不可编辑
当我寻求帮助时,我想迭代一个范围,但我不知道迭代在哪里,也不知道如何修复这个错误
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
min()
和max()
是期望将iterables作为参数的函数。他们分别在这些可分解物中找到最小和最大的元素
按照您调用np.random.laplace()
的方式,它将返回一个单独的浮点值,这不是一个iterable
min()
和max()
是期望将iterables作为参数的函数。他们分别在这些可分解物中找到最小和最大的元素
根据您调用
np.random.laplace()
的方式,它将返回一个浮点值,该值不是一个iterable。如果您希望从numpy.random.laplace
返回iterable,则必须在(可选)第三个参数中指定要返回的数组的形状
e、 g.抽取10000个样本:
mean, stdv, n = 40.0, 2.0, 10000
raw_data = np.random.laplace(mean, stdv/np.sqrt(2),n)
# example of how to digitize data
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
rng = stop - start
digitisation = 8192.0
bins = np.arange(start, stop, rng / digitisation)
如果您想要从
numpy.random.laplace
返回一个iterable,则必须在(可选)第3个参数中指定要返回的数组的形状
e、 g.抽取10000个样本:
mean, stdv, n = 40.0, 2.0, 10000
raw_data = np.random.laplace(mean, stdv/np.sqrt(2),n)
# example of how to digitize data
start, stop = int(min(raw_data - 1)), int(max(raw_data + 1))
rng = stop - start
digitisation = 8192.0
bins = np.arange(start, stop, rng / digitisation)
raw_data
是一个float
,您如何获取该数据的min
?我想你忘了告诉我你想画多少个样本,np.random.laplace(平均值,stdv/np.sqrt(2),n)
我的理解是,np.random.laplace(平均值,stdv/np.sqrt(2))
是不可编辑的,但我不知道最小值和最大值在它们上面迭代过。老实说,我不知道在这些调用中输入第二个参数是什么。@abhjeetbullar除了mean
和stdv/np.sqrt(2)
之外,还应该传递n
,这样它将返回一个n
采样元素数组scory Kramer你完全正确,非常感谢你,我简直不敢相信我错过了原始数据是一个浮点数
,你怎么能取它的最小值
?我想你忘了告诉我你想画多少个样本,np.random.laplace(平均值,stdv/np.sqrt(2),n)
我的理解是,np.random.laplace(平均值,stdv/np.sqrt(2))
是不可编辑的,但我不知道最小值和最大值在它们上面迭代过。老实说,我不知道在这些调用中输入第二个参数是什么。@abhjeetbullar除了mean
和stdv/np.sqrt(2)
之外,还应该传递n
,这样它将返回一个n
采样元素数组scory Kramer你完全正确,非常感谢你,我简直不敢相信我错过了!考虑到他们上面有n=10000
,我认为真正的解决办法是他们调用laplace
成为raw_data=np.random.laplace(mean,stdv/np.sqrt(2),n)
,这样他们就有了一个采样值数组。但是你的答案显然仍然有效。考虑到他们上面有n=10000
,我认为真正的解决办法是他们调用laplace
成为raw_data=np.random.laplace(mean,stdv/np.sqrt(2),n)
,这样他们就有了一个采样值数组。但你的答案显然仍然有效。