城歌 2025-02-16 14:23:37
可以说,这样做的更多“ bash Native”方法是:
IFS=, read -r -a id_parts < <(id)
printf '%s\n' "${id_parts[@]:1}"
- 请参阅如何将字符串分为bash中的数组?
ifs =的说明,读取-r -a id_parts ...
。 - 请参阅 processSubStitution -Greg的Wiki 用于解释
&lt; &lt;(id)
。 - 请参阅如何在bash 和 printf'%s \ n'” $ {array [@]}“要打印一行每个数组元素?以说明
printf'%s \ n'” $ {id_parts [@]:1}“
。
城歌 2025-02-16 12:08:09
数据“日期”和“时间”分为单独的列。我还创建了DateTime列。结果,数据帧看起来像这样:
source date time datetime
0 Investing.com 2017-05-11 08:00:00 2017-05-11 08:00:00
1 Investing.com 2017-05-11 12:00:00 2017-05-11 12:00:00
2 Investing.com 2017-05-11 16:00:00 2017-05-11 16:00:00
3 yahoo.com 2017-05-11 09:00:00 2017-05-11 09:00:00
4 yahoo.com 2017-05-11 12:00:00 2017-05-11 12:00:00
5 yahoo.com 2017-05-11 15:00:00 2017-05-11 15:00:00
6 yahoo.com 2017-05-12 06:00:00 2017-05-12 06:00:00
7 yahoo.com 2017-05-12 12:00:00 2017-05-12 12:00:00
8 yahoo.com 2017-05-12 18:00:00 2017-05-12 18:00:00
接下来,我创建一个函数my_func并将分组结果保存到数据框架中。我重置多索引,删除额外的列,然后将列重命名为结果。事实证明有点华丽,也许有人会更轻松。
import pandas as pd
df['datetime'] = df['date'].str.cat(df['time '], sep =" ")
df['datetime'] = pd.to_datetime(df['datetime'])
def my_func(x):
result = str(df.loc[x.index,'datetime'].diff().mean())[7:]
return result
df1 = pd.DataFrame(df.groupby(['source','date'])['date'].apply(my_func))
df1 = df1.stack(0).reset_index()
df1 = df1.drop(columns='level_2')
df1.rename(columns={0: 'Average_Daily_time'}, inplace=True)
print(df1)
输出
source date Average_Daily_time
0 Investing.com 2017-05-11 04:00:00
1 yahoo.com 2017-05-11 03:00:00
2 yahoo.com 2017-05-12 06:00:00
城歌 2025-02-16 08:59:57
如果要使用
因此以太更改为
current_timestamp()
或
CURRENT_TIMESTAMP
城歌 2025-02-16 06:11:54
这应该做您想要的事情,但嵌套功能少得多。
library(dplyr)
df %>% mutate(Classification = case_when(AGE2 <= 6 ~ "",
BMI2 < 18.5 ~ "Underwwight",
BMI2 < 25 ~ "Normal weight",
BMI2 < 30 ~ "Overwwight",
BMI2 >= 30 ~ "Obese"
))
这将为重量分类创建一个额外的列。
A tibble:6 x 3
AGE2 BMI2 Classification
<dbl> <dbl> <chr>
15 22.50087 Normal weight
17 24.88647 Normal weight
14 22.70773 Normal weight
9 23.49076 Normal weight
5 22.14871
16 23.10811 Normal weight
6 rows
如果需要,这也很容易作为功能应用。
城歌 2025-02-15 23:17:27
这是一种方法
ratio = [2, 3, 5]
ratio_dec = np.divide(ratio, sum(ratio))
df['ratio'] = df['values'].apply(lambda x: np.round(np.multiply(x, ratio_dec) ,0))
df.explode('ratio')
ID values ratio
0 1 10 2.0
0 1 10 3.0
0 1 10 5.0
1 2 20 4.0
1 2 20 6.0
1 2 20 10.0
2 3 30 6.0
2 3 30 9.0
2 3 30 15.0
城歌 2025-02-15 14:04:46
只需在每列中使用一个子查询,即提及两者之间所需的时间戳,还请确保您的start_time和end_time列是时间戳类型。有关更多信息,请共享表结构,示例数据和预期输出
城歌 2025-02-15 12:02:31
我还努力寻找可以选择的HSV值(最终选择区域)。通过大量谷歌搜索,我制作了这个小脚本来检查图像中的HSV值。
它打开您的图像(调整cv2.imread
的路径)。
当您单击图像的兴趣点时,它会在图像中的该位置打印鼠标单击和HSV值的位置。
import cv2
def on_mouse(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
print("HSV values at ({}, {}): {}".format(x, y, hsv[y, x]))
img = cv2.imread(‘\path\to\your\image\piccie.png’)
cv2.namedWindow("image")
cv2.setMouseCallback("image", on_mouse)
while True:
cv2.imshow("image", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
城歌 2025-02-15 11:53:44
为此使用std :: vector。例如:
std::vector<int> values;
values.resize(n);
内存将分配在堆上,但这仅具有一个小的性能弊端。此外,明智的做法是不要在堆栈上分配大型数据,因为它的尺寸相当有限。
城歌 2025-02-15 09:13:52
有点混乱
library(dplyr)
library(reshape2)
frame2 <- frame %>%
reshape2::melt(id.vars = "id") %>%
filter(value != "NA") # or na.omit()
frame2
res <- list()
l <- unique(frame2$variable)
for (i in 1:length(l)){
dd <- frame2 %>%
filter(variable == l[i]) %>%
group_by(variable, value) %>%
summarise(n = n()) %>%
mutate(freq = n/sum(n)) %>%
pivot_wider(id_cols = value, values_from = c(n, freq), names_from = variable) %>%
column_to_rownames(var = "value")
colnames(dd) <- c(as.character(l[i]), "per")
res[[i]] <- dd
}
res
[[1]]
A per
cat 3 0.75
dog 1 0.25
[[2]]
B per
cat 3 0.375
dog 5 0.625
[[3]]
C per
cat 2 0.5
dog 2 0.5
城歌 2025-02-14 00:14:39
- 尝试将
localhost
更改为firebase命令行和应用程序中的计算机IP。一些模拟器,例如iOS模拟器,无法理解本地主机。 - 请粘贴A 完全可重复的样本,而不仅仅是一部分。
- 尝试到
等待firebase.initializeapp();
main 函数,而不是initstate
- 首先在端口8080上手动检查Firebase Server并查看Firebase Server是否确实有效
城歌 2025-02-13 23:03:28
作为快速n脏修复,这对我有用:
在有问题的导入之前添加这2行:
import sys
sys.path.append('C:\\Python27\\Lib\site-packages')
城歌 2025-02-13 07:02:39
作为我自己学习的一种练习,我给了它,并提出了以下方法。创建一个定制的小部件,它看起来像是如此简单的东西,看起来像是很多代码……但是它似乎按照预期的方式工作,并且可以以各种方式修改,扩展和集成与其他元素。
用法:const Maxintfield(最大:100),
实现:
class MaxIntField extends StatefulWidget {
const MaxIntField({Key? key, this.max = 1}) : super(key: key);
final int max;
@override
State<MaxIntField> createState() => _MaxIntFieldState();
}
class _MaxIntFieldState extends State<MaxIntField> {
final TextEditingController _controller = TextEditingController();
@override
void initState() {
super.initState();
_controller.value.copyWith(text: '0');
_controller.addListener(() {
if (_controller.text.isNotEmpty && _controller.text != '0') {
int intVal = int.parse(_controller.text);
if (intVal > widget.max) {
setState(() {
_controller.value =
_controller.value.copyWith(text: widget.max.toString());
_showMyDialog();
});
} else if (_controller.text != intVal.toString()) {
//remove leading '0'
setState(() {
_controller.value =
_controller.value.copyWith(text: intVal.toString());
});
}
}
});
}
// assuming using Material
_showMyDialog() async {
showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('AlertDialog Title'),
content: Text('This field is limited to ${widget.max}'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return TextFormField(
controller: _controller,
keyboardType: TextInputType.number,
);
}
}
城歌 2025-02-13 05:58:44
有人用纯粹的numpy回答了我:
import numpy as np
rand = np.random.default_rng(seed=0)
a = rand.uniform(low=-1, high=1, size=(10, 1))
b = rand.uniform(low=-1, high=1, size=(10, 6))
def signs():
sa = np.sign(a)
return sa * (sa == np.sign(b))
def main():
signs()
return
if __name__ == '__main__':
main()
%timeit signs()
10.2 µs ± 678 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
Ruby没有“内部”或“外部”类的概念。听起来您来自Beta,Scala或Newspeak之类的语言,但Ruby不是Beta,Scala或Newspeak。一般而言,任何编程语言都可以正常工作,而编程语言的规范是如何有效的,而不是某些其他编程语言的规范如何工作。 Beta,Scala和Newspeak的课程嵌套了,但Ruby没有。
在Ruby中,您可以词法嵌套 a class 定义,但这不会创建嵌套类。如果将类的定义嵌套在另一个类的定义中,则不会在这两个类之间创建任何类型的关系。没有任何。您不能从另一个类中“访问一个类别的变量/方法”,因为您可以遵循的两个类之间没有关系以获取这些变量/方法。
嵌套类定义唯一的事情是命名空间由外部类的内类定义定义的常数。就是这样。这两个类之间没有关系,唯一的关系是 constant 和类之间。
只是不可能。
在Ruby中创建关系的方法是 shastaritance ,而不是嵌套(因为没有嵌套)。在Ruby中创建对象之间的关系的方法是关联,聚合或组成,而不是嵌套。
Ruby IS 足够灵活,可以实现像“适当” beta式内部类别的行为。请记住,一个内类是在外部类的对象实例中“嵌套”的。我们可以使用一个实例变量模拟这一点:
请注意,我使内部类从外部类中继承:那是在Ruby中进行行为共享的方法。您需要具有某种形式的继承或关联关系。嵌套不会产生关系。
Ruby does not have a concept of "inner" or "outer" classes. It sounds like you are coming from a language like BETA, Scala, or Newspeak, but Ruby is not BETA, Scala, or Newspeak. As a general rule, any programming language works exactly how the specification for the programming language says it works, not how the specification for some other programming language says it works. BETA, Scala, and Newspeak have nested classes, but Ruby has not.
In Ruby, you can lexically nest a class definition, but that does not create a nested class. If you nest the definition of a class inside the definition of another class, that does not create any sort of relationship whatsoever between those two classes. None. You cannot "access variables/methods" of one class from the other class because there is no relationship between those two classes you could follow in order to get at those variables/methods.
The only thing a nested class definition does, is namespace the constant defined by the inner class definition to the outer class. That's it. There is no relationship between the two classes, the only relationship is between the constant and the class.
It is just not possible.
The way to create relationships between classes in Ruby is inheritance, not nesting (because there is no nesting). The way to create relationships between objects in Ruby is association, aggregation, or composition, not nesting.
Ruby is flexible enough to implement something that behaves like a "proper" BETA-style inner class. Remember, an inner class is "nested" inside an object instance of the outer class. We can emulate that using an instance variable:
Please note that I made the inner class inherit from the outer class: that is the way to do behavior sharing in Ruby. You need to have some form of inheritance or association relationship. The nesting does not create a relationship.
在Ruby中,如何在外部类中定义内部类访问变量/方法?