arrays - 如何制作数组的np数组
问题描述
嘿,我想这可能已经得到了回答,但是我找不到我正在寻找的东西。下面是代码:
positiveData = np.array([])
negativeData = []
with AedatFile('someFile') as f:
# loop through the "frames" stream
for e in f['events'].numpy():
for event in e:
time, x, y, polarity, _, _ = event
if polarity == 1:
data = np.array([time, x, y, polarity])
print(data)
positiveData = np.append(positiveData,data)
print(positiveData)
else:
data = [time, x, y, polarity]
negativeData.append(data)
我希望代码看起来像这样:
[[1,2,3,4],
[1,2,3,4],
....]
我打算用它来制作一个 3d 图,所以我想要一个数组,这样我就可以轻松地 plot3d(array[0][:],array[1][:],array[2][:])
欢呼所有人。
这是下面要求的一组样本数据。我不能粘贴更多,因为它说我的评论主要是代码,不允许我在不添加更多文本的情况下发布更多内容,这非常愚蠢。
[(1612584805989190, 254, 304, 1, 0, 0)
(1612584805989190, 254, 283, 1, 0, 0)
(1612584805989190, 254, 286, 1, 0, 0) ...
(1612584805999148, 596, 20, 1, 0, 0)
(1612584805999162, 549, 60, 1, 0, 0)
(1612584805999189, 461, 225, 0, 0, 0)]
[(1612584806009235, 512, 31, 1, 0, 0)
(1612584806009263, 419, 274, 1, 0, 0)
(1612584806009287, 338, 188, 0, 0, 0) ...
(1612584806019188, 214, 241, 0, 0, 0)
(1612584806019188, 214, 237, 0, 0, 0)
(1612584806019189, 211, 234, 0, 0, 0)]
解决方案
尝试修改为
positiveData = np.append( positiveData, [data] )
或者
data = np.array( [[ time, x, y, polarity ]] )
append 函数将在数组目标 https://numpy.org/doc/stable/reference/generated/numpy.append.html中附加(嵌入)给定的数组
推荐阅读
- android - 输入字符串错误:“12”Android Studio
- php - 关于表的联接:关联 uid 和 gid?
- javascript - 递归 async/await 使 React App 崩溃
- tensorflow - Tensorflow 线性回归房价
- javascript - Javascript 和 Python - Django
- javascript - 为我自己的语言开发 JavaScript linting 工具的最佳实践?
- php - 尝试打印命令的实时输出时,在 system() 命令之后未执行 PHP 代码
- javascript - 获取国家/地区的 id 会返回 Expression 'mid = s.id' is non-assignable
- mysql - SQL命令二合并
- r - R:将等级 1 分配给预定义的最大值