小编ksk*_*skp的帖子

从Shell脚本向Python传递参数

我写了一个小shell脚本,看起来像这样:

cd models/syntaxnet
var1=$(jq --raw-output '.["avl_text"]' | syntaxnet/demo.sh)
echo $var1
python /home/sree/python_code1.py $var1
Run Code Online (Sandbox Code Playgroud)

python_code1.py看起来像这样:

import sys

data = sys.argv[1]
print "In python code"
print data
print type(data)
Run Code Online (Sandbox Code Playgroud)

现在,我的shell脚本中echo $ var1的输出正是我想要看到的:

1 Check _ VERB VB _ 0 ROOT _ _ 2 out _ PRT RP _ 1 prt _ _ 3 this _ DET DT _ 4 det _ _ 4 video _ NOUN NN _ 1 dobj _ _ 5 about _ ADP IN _ 4 prep …

python shell arguments

6
推荐指数
2
解决办法
2万
查看次数

Python:将列表附加到另一个列表并清除第一个列表

所以这只是让我大吃一惊.我正在编写一个python代码,我在其中创建一个列表,将其附加到主列表并清除第一个列表以向其添加更多元素.当我清除第一个列表时,即使主列表也被清除.我在很多列表中附加并清除但从未观察到这一点.

list1 = []
list2 = []
list1 = [1,2,3]
list2.append(list1)
list1
[1, 2, 3]
list2
[[1, 2, 3]]
del list1[:]
list1
[]
list2
[[]]
Run Code Online (Sandbox Code Playgroud)

我知道这会附加字典,但我不知道如何处理列表.有人可以详细说明吗?

我正在使用Python2.7

python list

5
推荐指数
2
解决办法
7199
查看次数

创建符号链接失败

我正在尝试在我的 CentOS 6.7 机器上升级 glibcxx。我做了这里给出的步骤。

现在,当我这样做时:

strings /opt/google/chrome/lib/libstdc++.so.6 | grep GLIBC
Run Code Online (Sandbox Code Playgroud)

我列出了 GLIBCXX_3.4 到 GLIBCXX_3.4.22。

为了在我的 Syantaxnet 构建中使用这个文件,我创建了一个符号链接:

ln -s /opt/google/chrome/lib/libstdc++.so.6 /usr/lib64/libstdc++.so.6
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误:

ln: creating symbolic link `/usr/lib64/libstdc++.so.6': File exists
Run Code Online (Sandbox Code Playgroud)

编辑1:

我认为错误是由于相同的文件名并将 /opt/google/chrome/lib/libstdc++.so.6 重命名为 libstdc++.so.6_new。命令仍然失败。

有人可以帮我解决这个问题吗?另外,这是错误的解决方案:

/usr/local/bin/bazel: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by /usr/local/bin/bazel)
/usr/local/bin/bazel: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/local/bin/bazel)
Run Code Online (Sandbox Code Playgroud)

linux symlink centos6 syntaxnet

3
推荐指数
1
解决办法
3万
查看次数

Filter columns using multiple conditions in Pig

I need to write a pig script where I am finding the average values of several columns and getting only those rows whose all column values are greater than the computed averages. My script is:

i2 = GROUP i1 all;
i3 = FOREACH i2 GENERATE AVG(i1.user_followers_count) AS avg_user_followers_count, AVG(i1.avl_user_follower_following_ratio) AS avg_avl_user_follower_following_ratio, AVG(i1.user_total_liked) AS avg_user_total_liked, AVG(i1.user_total_posts) AS avg_user_total_posts, AVG(i1.user_total_public_lists) AS avg_user_total_public_lists, AVG(i1.avl_user_total_retweets) AS avg_avl_user_total_retweets, AVG(i1.avl_user_total_likes) AS avl_user_total_likes, AVG(i1.avl_user_total_replies) AS avg_avl_user_total_replies, AVG(i1.avl_user_engagements) AS avl_avl_user_engagements, AVG(i1.user_reply_to_reply_count) AS avg_user_reply_to_reply_count;

top_inf = FILTER i1 BY …
Run Code Online (Sandbox Code Playgroud)

apache-pig

3
推荐指数
1
解决办法
6838
查看次数

R警告:newdata'有15行,但找到的变量有22行

我在这里读到的答案很少,但我恐怕无法找到答案.

我的R代码是:

colors <- bmw[bmw$Channel=="Colors" & bmw$Hour=20,]
colors_test <- tail(colors, 89)
colors_train <- head(colors, 810)

colors_train_agg <- aggregate(colors_train$Impressions, list(colors_train$`Position of Ad in Break`), FUN=mean, na.rm=TRUE)
colnames(colors_train_agg) <- c("ad_position", "avg_impressions")
lm_colors <- lm(colors_train_agg$avg_impressions ~ poly(colors_train_agg$ad_position, 12))
 summary(lm_colors)

colors_test_agg <- aggregate(colors_test$Impressions, list(colors_test$`Position of Ad in Break`), FUN=mean, na.rm=TRUE)
colnames(colors_test_agg) <- c("ad_position", "avg_impressions")
new.df <- data.frame(colors_test_agg$ad_position)
colnames(new.df) <- c("ad_position")
colors_test_test <- predict(lm_colors, newdata=new.df)
Run Code Online (Sandbox Code Playgroud)

所以我对训练和测试数据都有完全相同的列名.我仍然收到警告:

Warning message: 'newdata' had 15 rows but variables found have 22 rows

有人可以提出什么是错的吗?另外,我想知道我是否以正确的方式做到了.

此外,将非常感谢关于如何计算模型精度的一些指示.谢谢!

r prediction non-linear-regression

1
推荐指数
1
解决办法
8979
查看次数

在Python中用单词替换货币符号

我有一个大约 50000 条推文的文件,我想用单词替换所有货币符号,这样就$10变成了 10 dollars.

我怎样才能在Python中做到这一点?

我可以使用正则表达式找到符号:[$][0-9]+。我不知道如何用文字替换它,以及交换数字和符号的位置。

我的推文只有$符号,没有其他货币符号。请帮忙。

python regex python-2.7

-1
推荐指数
1
解决办法
959
查看次数