- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个数据集,我在其中存储不同类/子类型的副本(不确定如何调用它),然后存储每个类/子类型的属性。本质上,有 5 个子类型/类,每个子类型/类有 4 个重复,以及测量的 100 个属性。
是否有像 np.ravel
或 np.flatten
这样的方法可以使用 Xarray
合并 2 个维度?
在此,我想合并 dims subtype
和 replicates
所以我有一个二维数组(或 pd.DataFrame
和 属性与子类型/复制
。
它不需要格式为“coord_1 | coord_2”或任何格式。如果它保留原始坐标名称,将会很有用。也许有类似 groupby
的东西可以做到这一点? Groupby
总是让我感到困惑,所以如果它是 xarray
的原生功能,那就太棒了。
import xarray as xr
import numpy as np
# Set up xr.DataArray
dims = (5,4,100)
DA_data = xr.DataArray(np.random.random(dims), dims=["subtype","replicates","attributes"])
DA_data.coords["subtype"] = ["subtype_%d"%_ for _ in range(dims[0])]
DA_data.coords["replicates"] = ["rep_%d"%_ for _ in range(dims[1])]
DA_data.coords["attributes"] = ["attr_%d"%_ for _ in range(dims[2])]
# DA_data.coords
# Coordinates:
# * subtype (subtype) <U9 'subtype_0' 'subtype_1' 'subtype_2' ...
# * replicates (replicates) <U5 'rep_0' 'rep_1' 'rep_2' 'rep_3'
# * attributes (attributes) <U7 'attr_0' 'attr_1' 'attr_2' 'attr_3' ...
# DA_data.dims
# ('subtype', 'replicates', 'attributes')
# Naive way to collapse the replicate dimension into the subtype dimension
desired_columns = list()
for subtype in DA_data.coords["subtype"]:
for replicate in DA_data.coords["replicates"]:
desired_columns.append(str(subtype.values) + "|" + str(replicate.values))
desired_columns
# ['subtype_0|rep_0',
# 'subtype_0|rep_1',
# 'subtype_0|rep_2',
# 'subtype_0|rep_3',
# 'subtype_1|rep_0',
# 'subtype_1|rep_1',
# 'subtype_1|rep_2',
# 'subtype_1|rep_3',
# 'subtype_2|rep_0',
# 'subtype_2|rep_1',
# 'subtype_2|rep_2',
# 'subtype_2|rep_3',
# 'subtype_3|rep_0',
# 'subtype_3|rep_1',
# 'subtype_3|rep_2',
# 'subtype_3|rep_3',
# 'subtype_4|rep_0',
# 'subtype_4|rep_1',
# 'subtype_4|rep_2',
# 'subtype_4|rep_3']
最佳答案
是的,这正是 .stack
的用途:
In [33]: stacked = DA_data.stack(desired=['subtype', 'replicates'])
In [34]: stacked
Out[34]:
<xarray.DataArray (attributes: 100, desired: 20)>
array([[ 0.54020268, 0.14914837, 0.83398895, ..., 0.25986503,
0.62520466, 0.08617668],
[ 0.47021735, 0.10627027, 0.66666478, ..., 0.84392176,
0.64461418, 0.4444864 ],
[ 0.4065543 , 0.59817851, 0.65033094, ..., 0.01747058,
0.94414244, 0.31467342],
...,
[ 0.23724934, 0.61742922, 0.97563316, ..., 0.62966631,
0.89513904, 0.20139552],
[ 0.21157447, 0.43868899, 0.77488211, ..., 0.98285015,
0.24367352, 0.8061804 ],
[ 0.21518079, 0.234854 , 0.18294781, ..., 0.64679141,
0.49678393, 0.32215219]])
Coordinates:
* attributes (attributes) |S7 'attr_0' 'attr_1' 'attr_2' 'attr_3' ...
* desired (desired) object ('subtype_0', 'rep_0') ...
生成的堆叠坐标是一个 pandas.MultiIndex
,其值由元组给出:
In [35]: stacked['desired'].values
Out[35]:
array([('subtype_0', 'rep_0'), ('subtype_0', 'rep_1'),
('subtype_0', 'rep_2'), ('subtype_0', 'rep_3'),
('subtype_1', 'rep_0'), ('subtype_1', 'rep_1'),
('subtype_1', 'rep_2'), ('subtype_1', 'rep_3'),
('subtype_2', 'rep_0'), ('subtype_2', 'rep_1'),
('subtype_2', 'rep_2'), ('subtype_2', 'rep_3'),
('subtype_3', 'rep_0'), ('subtype_3', 'rep_1'),
('subtype_3', 'rep_2'), ('subtype_3', 'rep_3'),
('subtype_4', 'rep_0'), ('subtype_4', 'rep_1'),
('subtype_4', 'rep_2'), ('subtype_4', 'rep_3')], dtype=object)
关于python - 将 3 维 xr.DataArray (Xarray) 展平/拆解/折叠成沿轴的二维?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38494300/
很想尝试将 BufferedImages 导出为 JPEG-XR,但找不到导出工具来添加到 java 工作流程。最好有一个 JAI 插件在那里......我用谷歌搜索 about无济于事。希望这里有人
8XRremote 不工作。Android 应用程序通过 WIFI 连接到 Windows。在统一控制台中有以下日志: C:/Users/Tim/AppData/Local/Android/Sdk/p
我有一个在 UWP 项目中使用的类库项目。如果我在类库中添加任何 usercontrol xaml 文件并构建它,它构建得很好。但是 UWP 项目给出了找不到 .xr 文件的错误。 我是否需要将任何文
我正在使用 8th Wall XR 1.0.9.3 版,我认为 XRController 类存在问题。 XRCameraController 类无法使用 XRController.GetCameraP
我的用户个人资料图片在旧版本上看起来不错(圆形),但在我 friend 的 XR 手机上看起来像椭圆形。我不知道为什么。下面是 Storyboard约束的图片和我的约束代码。 Oval Shaped
我已将 bottomAppBar 与我的 Flutter 应用集成,并为其添加了 FAB。但这并没有正确地显示我。请检查附图: 最佳答案 将您的 Widget 包裹在 SafeArea 中: retu
Labs 导读 虚拟现实(Virtual Reality,VR)、增强现实(Augmented Reality,AR)等业务以其三维化、自然交互、空间计算等完全不同于当前移动互联网
我的项目针对 iOS - 11 及更高版本。它具有适用于具有适当尺寸的 XR 和 XS Max 的正确启动图像 Assets 。在模拟器上,我的应用程序在 XR 和 XS Max 上都能按预期运行。
我目前没有 iPhone XR 设备来查询 AVCaptureDeviceDiscoverySession XR 后置摄像头上可用的设备类型。 iPhone XR 后置摄像头是 AVCaptureDe
当我通过docker使用mysql时,我发现一个问题:在mysql配置文件my.cnf中,我设置如下: [mysqld] datadir=/var/lib/mysql user=Tim ... 但是你
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我如何编码 System.Drawing.Bitmap (v4.0) 到 JPEG XR 流? 最佳答案 这可以通过 extension method 解决: using System.Drawing
当我使用以下两种方法之一在新模拟器实例中实例化 AVAssetExportSession 对象时: AVAsset *videoAsset = [AVAsset assetWithURL:videoU
iPhoneXr/iPhone11 有两张 sim 卡,所以变量 serviceSubscriberCellularProviders 会有两个值。有没有办法获取当前正在使用的那个? ========
我目前遇到了一个仅在 iPhone XR 上报告的错误。 我们有一个自定义相机,可以强制旋转为横向,完成后,它会强制 View 返回纵向。 只有使用 iPhone XR 的用户提到了该错误。它发生在调
我有一个小的 UIImageView 用于显示用户的个人资料照片。这在 iPhone 6S 上看起来不错,但是当我在 iPhone XR 上运行它时,图像在屏幕上缩小为一个小点。我尝试了不同型号的模拟
iPhone XR 屏幕分辨率根据屏幕截图、苹果网站等: 828x1792 根据 Swift 的 iPhone XR 屏幕分辨率: 375x812(或 750x1624) 为什么以及如何处理?! 注意
我正在使用 Python 3 处理显微镜生成的文件,该文件本质上是数千张 Jpeg XR 压缩图像的集合。我需要将它们全部读入内存。现在我正在以二进制模式读取数据,将它们保存在 .jxr 文件中并调用
**我已尝试权限但仍然收到此错误 Array ( [0] => sh: 1: /var/www/nodejs/tmp: Permission denied ) 该命令是从Laravel(MVC PHP
我是一名优秀的程序员,十分优秀!