- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的函数内部有一个 DataFrame:
using DataFrames
myservs = DataFrame(serverName = ["elmo", "bigBird", "Oscar", "gRover", "BERT"],
ipAddress = ["12.345.6.7", "12.345.6.8", "12.345.6.9", "12.345.6.10", "12.345.6.11"])
myservs
5x2 DataFrame
| Row | serverName | ipAddress |
|-----|------------|---------------|
| 1 | "elmo" | "12.345.6.7" |
| 2 | "bigBird" | "12.345.6.8" |
| 3 | "Oscar" | "12.345.6.9" |
| 4 | "gRover" | "12.345.6.10" |
| 5 | "BERT" | "12.345.6.11" |
如何编写函数来获取名为 server
的单个参数,不区分大小写,与 myservs[:serverName] 中的
code> DataArray,并返回匹配对应的server
参数匹配ipAddress
?
在 R 中,这可以通过使用来完成
myservs$ipAddress[grep("server", myservs$serverName, ignore.case = T)]
我不希望有人使用 ElMo
或 Elmo
作为 服务器
,或者 serverName
保存为 elmo
或 ELMO
。
最佳答案
我引用了如何在 R 中完成任务并尝试使用 DataFrames
pkg 来完成此任务,但我这样做只是因为我来自 R
并且我刚刚学习Julia
。我向同事询问了很多问题,以下是我们得出的结论:
This task is much cleaner if I was to stop thinking in terms of
vectors
inR
.Julia
runs plenty fast iterating through a loop.Even still, looping wouldn't be the best solution here. I was told to look into Dicts (check here for an example).
Dict()
,zip()
,haskey()
, andget()
blew my mind. These have many applications.My solution doesn't even need to use the
DataFrames
pkg, but instead uses Julia'sMatrix
andArray
data representations. By usinglet
we keep the global environment clutter free and the server name/ip list stays hidden from view to those who are only running the function.In the sample code, I'm recreating the server matrix every time, but in reality/practice I'll have a permission restricted delimited file that gets read every time. This is OK for now since the delimited files are small, but this may not be efficient or the best way to do it.
# ONLY ALLOW THE FUNCTION TO BE SEEN IN THE GLOBAL ENVIRONMENT
let global myIP
# SERVER MATRIX
myservers = ["elmo" "12.345.6.7"; "bigBird" "12.345.6.8";
"Oscar" "12.345.6.9"; "gRover" "12.345.6.10";
"BERT" "12.345.6.11"]
# SERVER DICT
servDict = Dict(zip(pmap(lowercase, myservers[:, 1]), myservers[:, 2]))
# GET SERVER IP FUNCTION: INPUT = SERVER NAME; OUTPUT = IP ADDRESS
function myIP(servername)
sn = lowercase(servername)
get(servDict, sn, "That name isn't in the server list.")
end
end
# Test it out
myIP("SLIMEY")
#>"That name isn't in the server list."
myIP("elMo")
#>"12.345.6.7"
关于regex - DataArray 不区分大小写的匹配,返回匹配的索引值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29426542/
我正在尝试使用有关单元格的一些元信息填充 DataArray,以将其添加到数据集中。 airtemps = xr.tutorial.load_dataset('air_temperature') ai
DataArray.mean 不保留取决于应用平均值的维度的坐标。 注意:XLAT 和 XLONG 与时间无关;然而,一些 netcdf 文件具有沿这两个方向的时间坐标。 我有这个 netcdf 文件
我的函数内部有一个 DataFrame: using DataFrames myservs = DataFrame(serverName = ["elmo", "bigBird", "Oscar",
我无法弄清楚 xarray 的一些基本使用模式。这是我过去可以在 numpy 中轻松完成的事情:(在另一个数组中设置满足特定条件的元素) import numpy as np q_index = np
在 xarray 中使用 DataArray 对象是查找所有具有值 != 0 的单元格的最佳方法。 例如在 Pandas 我会做 df.loc[df.col1 > 0] 我的具体例子是我试图查看 3
对于我的 Python 包 numericalmodel这应该有助于对简单的数值模型进行原型(prototype)设计,我为自描述数据集编写了类。我最近偶然发现了很棒的 xarray library现
很简单的问题,但我在网上找不到答案。我有一个 Dataset我只想添加一个名为 DataArray到它。类似 dataset.add({"new_array": new_data_array}) .我
假设我有以下 DataArray arr = xarray.DataArray(np.arange(6).reshape(2,3), dims=['A'
假设以下代码具有 xarray.DataArray有两个维度和一个坐标: import numpy as np from xarray import DataArray data = np.rando
我有一个 xarray DataArray,它的形状如下所示 (1,5,73,144,17),我正在尝试删除或删除“级别”坐标。所以,最终,我需要变量具有形状 = (1,5,73,144)。 stdn
我有一个 3 维 xarray DataArray,其中两个维度代表 x-y 网格,第三个维度代表彼此“堆叠”的网格层数。空的 DataArray 看起来像这样: import xarray as x
我正在尝试向 DataArray 添加一个具有一定长度的新维度。 我尝试使用expand_dims方法,其文档表明我应该能够做到这一点 http://xarray.pydata.org/en/stab
我正在使用 laravel 的 Model::create() 函数在数据库中创建一个新条目,但我传递到该函数的数组失败,因为它删除了其中一行。 这是我的数组全静态。这也符合我的数据库表的样子。 $d
我有一个 xarray.DataArray: array([ 5.437614e+01, 2.090367e+02, 3.687384e+02, ..., 5.121467e-02,
我有一个一维的 DataArray,每个值对应一个 ID。我正在尝试以相同的格式创建一个新数组,其中包含值超出限制的任何情况下的值和 ID 我尝试过使用xr.DataArray.where(condi
我需要向 DataArray 添加一个维度,填充新维度中的值。这是原始数组。 a_size = 10 a_coords = np.linspace(0, 1, a_size) b_size = 5 b
我对python有点陌生。我有一个 xarray DataArray 包含一个由浮点数组成的变量。这些浮点数应该是秒。我想将这些浮点数添加到给定日期: 2021-01-01 00:00:00 + 1
我有一个名为 rio 的 DataArray 对象。 In [59]: rio Out[59]: array([[[0, 0, ..., 0, 0], [0, 0, ..., 0,
我已经从多个源 hdf5 文件构建了一个巨大的 dask 数组。 假设数据仅来自一个 hdf5 文件: import dask.array as da import h5py import xarra
关注 How to add vectors to the columns of some array in Julia? ,我想对 DataArrays 进行一些类似的说明。 让 y=randn(10
我是一名优秀的程序员,十分优秀!