我有一个 Python在debuggexregex中运行良好:
但是,当我在 Python 控制台中执行此操作时:
import re
rgx = re.compile(r'(?<="careerJobAdsList", ){"jobAds":.*}](?=,"nodes":)')
st = 'widget("careerJobAdsList", {"jobAds":[{"id":607}],"nodes":[{"id":2,"parent_id"'
rgx.match(st)
>>> None
Run Code Online (Sandbox Code Playgroud)
我尝试转义 中的所有特殊字符rgx,但它不会改变输出。
我错过了什么吗?
这段代码需要一笔钱,Int并返回一个元组列表,表示所需金额或金币所需的最小金额.
purse :: Int -> [(String, Int)]
purse x
| x == 0 = [("$0", 0)]
| div x 200 >= 1 = before x 200 : after x 200
| div x 100 >= 1 = before x 100 : after x 100
| div x 50 >= 1 = before x 50 : after x 50
| div x 20 >= 1 = before x 20 : after x 20
| div x 10 >= 1 …Run Code Online (Sandbox Code Playgroud) 加入与Spark的标识导致公共密钥列在最终的数据集中重复:
val result = ds1.join(ds2, ds1("key") === ds2("key"))
// result now has two "key" columns
Run Code Online (Sandbox Code Playgroud)
这可以通过使用Seq而不是比较来避免,类似于USINGSQL中的关键字:
val result = ds1.join(ds2, Seq("key"))
// result now has only one "key" column
Run Code Online (Sandbox Code Playgroud)
但是,当使用公共密钥+另一个条件加入时,这不起作用,例如:
val result = ds1.join(ds2, ds1("key") === ds2("key") && ds1("foo") < ds2("foo"))
// result has two "key" columns
val result = ds1.join(ds2, Seq("key") && ds1("foo") < ds2("foo"))
// compile error: value && is not a member of Seq[String]
Run Code Online (Sandbox Code Playgroud)
目前摆脱这种情况的一种方法是在之后删除重复的列,但这非常麻烦:
val result = ds1.join(ds2, ds1("key") === ds2("key") && …Run Code Online (Sandbox Code Playgroud) 鉴于以下声明
data MyCustomString = MyCustomString String deriving (Show, Eq)
getSomeString :: IO String
Run Code Online (Sandbox Code Playgroud)
我想在上下文中将 的输出处理getSomeString为 a :IO MyCustomStringdo
do
cs_one <- getSomeString
cs_two <- getSomeString
-- at this point, `cs_one` and `cs_two` are of type `String`
-- how to construct them into `MyCustomString` instead with no additional lines?
Run Code Online (Sandbox Code Playgroud)
但是,getSomeString返回 anString而不是MyCustomString。我怎样才能使用MyCustomString构造函数,使cs_one和cs_two都在代码中的这一点上是类型MyCustomString?
我试过这个无济于事:
-- this does not work
do
MyCustomString cs_one <- getSomeString
MyCustomString …Run Code Online (Sandbox Code Playgroud) 我想知道是否可以在 Postgresql 中使用基于时间的窗口查询。
\n原始数据位于前三列(日期、销售员、金额):
\n| 日期 | 推销员 | 数量 | 3 滚动天数总和 |
|---|---|---|---|
| 2020-01-01 | 约翰 | 10 | 10 |
| 2020-01-02 | 约翰 | 15 | 25 |
| 2020-01-03 | 约翰 | 8 | 33 |
| 2020-01-04 | 约翰 | 12 | 35 |
| 2020-01-05 | 约翰 | 11 | 31 |
| 2020-01-01 | 丹尼尔 | 5 | 5 |
| 2020-01-02 | 丹尼尔 | 6 | 11 |
| 2020-01-03 | 丹尼尔 | 7 | 18 |
| 2020-01-04 | 丹尼尔 | 8 | 21 |
| 2020-01-05 | 丹尼尔 | 9 | 24 |
第四列表示该销售员在过去三个滚动日内的总金额。
\nPandas 有内置函数可以做到这一点,但我想不出任何方法可以使用内置sum() over ()语法在 Postgresql 中做到这一点。我能够做到的唯一方法是使用横向连接和子查询的复杂组合以及时间增量比较的条件,至少可以说这是不优雅的。
Pandas\' 方式(根据记忆,确切的语法可能略有不同) \xe2\x80\x94 无法获得任何简洁的信息:
\ndf.groupby(\'salesman\').rolling(\'3d\').sum()\nRun Code Online (Sandbox Code Playgroud)\n 我正在尝试获得以下输出:
[(1,5,54), (1,6,34), (1,7,16), (2,5,59), (2,6,29), (2,7,71), (3,5,44), (3,6,67), (3,7,24)]
Run Code Online (Sandbox Code Playgroud)
这是笛卡尔积,[1..3], [5..7]其中每个结果元组都获得一个随机数作为其第三个元素。
我试过下面的代码
[(1,5,54), (1,6,34), (1,7,16), (2,5,59), (2,6,29), (2,7,71), (3,5,44), (3,6,67), (3,7,24)]
Run Code Online (Sandbox Code Playgroud)
问题是这会生成一个随机数并一直重复(假设这次是 42):
[(1,5,42), (1,6,42), (1,7,42), (2,5,42), (2,6,42), (2,7,42), (3,5,42), (3,6,42), (3,7,42)]
Run Code Online (Sandbox Code Playgroud)
然后我想,当然,让我们实际生成length [1..3] * length [5..7]数字:
hello :: IO [(Int, Int, Int)]
hello = do
g <- getStdGen
let zyx = do
x <- [1..3]
y <- [5..7]
z <- take 1 $ randomRs (1, 100) g
pure (x, y, z)
pure zyx
Run Code Online (Sandbox Code Playgroud)
但现在这将随机数列表组合到产品中: …
在 CPU 上使用 PyTorch Lightning 时,一切正常。然而,当使用 GPU 时,我得到一个RuntimeError: Expected all tensors to be on the same device.
问题似乎来自于使用未传递给 GPU 的子模型列表的模型:
class LambdaLayer(LightningModule):
def __init__(self, fun):
super(LambdaLayer, self).__init__()
self.fun = fun
def forward(self, x):
return self.fun(x)
class TorchModel(LightningModule):
def __init__(self):
super(TorchModel, self).__init__()
self.cat_layers = [TorchCatEmbedding(cat) for cat in columns_to_embed]
self.num_layers = [LambdaLayer(lambda x: x[:, idx:idx+1]) for _, idx in numeric_columns]
self.ffo = TorchFFO(len(self.num_layers) + sum([embed_dim(l) for l in self.cat_layers]), y.shape[1])
self.softmax = torch.nn.Softmax(dim=1)
model = TorchModel()
trainer = Trainer(gpus=-1) …Run Code Online (Sandbox Code Playgroud) 我有这个文件utils.rs声明lazy_static如下:
extern crate geojson;
extern crate geo;
use self::geo::MultiPolygon;
use self::geojson::GeoJson;
use self::geojson::conversion::TryInto;
lazy_static! {
pub static ref LAND_POLYGONS: MultiPolygon<f64> = {
let input_string = include_str!("resources/land.geojson");
let mut polygons: Vec<Polygon<f64>> = vec![];
// ...
// add some polygons here
// ...
MultiPolygon(polygons)
};
}
Run Code Online (Sandbox Code Playgroud)
然后在main.rs我尝试使用LAND_POLYGONS如下:
#[macro_use]
extern crate lazy_static;
extern crate geo;
use self::geo::MultiPolygon;
use utils::LAND_POLYGONS;
fn main() -> Result<(), Box<Error>> {
lazy_static::initialize(&LAND_POLYGONS);
println!("{:?}", LAND_POLYGONS);
Ok(())
}
Run Code Online (Sandbox Code Playgroud)
这会产生以下编译器错误:
error[E0277]: `utils::LAND_POLYGONS` doesn't implement …Run Code Online (Sandbox Code Playgroud) 熊猫数据框的结构如下:
color price_blue price_red price_green
date
2019-01-01 green 10 20 30
2019-01-02 red 40 50 60
2019-01-03 blue 11 12 13
Run Code Online (Sandbox Code Playgroud)
我们如何price基于color每一行的列值添加一列:
color price_blue price_red price_green price
date
2019-01-01 green 10 20 30 30
2019-01-02 red 40 50 60 50
2019-01-03 blue 11 12 13 11
Run Code Online (Sandbox Code Playgroud)
尽管apply类似的解决方案似乎很容易,但是在这种情况下,由于数据集相对较大,因此需要向量化解决方案。
此外,类似的解决方案np.where仅需很少的颜色选择就可以很好地工作,但是在实际情况下,存在20多种不同的“颜色”,因此最终由于嵌套过多而变得不切实际where。
我试图让类型Shape重新使用类型Circle和Rectangle
data Point = Point {
x :: Float,
y :: Float
} deriving (Show)
data Circle = Circle {
c :: Point,
r :: Float
} deriving (Show)
data Rectangle = Rectangle {
p1 :: Point,
p2 :: Point
} deriving (Show)
-- the following obviously doesn't compile
data Shape = Circle Circle | Rectangle Rectangle deriving (Show)
Run Code Online (Sandbox Code Playgroud)
以上导致编译错误
Multiple declarations of ‘Circle’
18 | data Shape = Circle Circle | Rectangle Rectangle deriving …Run Code Online (Sandbox Code Playgroud) haskell ×4
python ×3
apache-spark ×1
constructor ×1
gpu ×1
list ×1
numpy ×1
pandas ×1
postgresql ×1
pytorch ×1
random ×1
regex ×1
rust ×1
scala ×1
static ×1
time-series ×1
types ×1