我有两个小数字段,一个精度为18,另一个精度为200。我想计算第一个不关心超过18的位,但是对于较大的数,我需要考虑
如果我使用# first we create all the "single" keywords, i e "old grandma" -> "old" and "grandma"
all_keyword_un <- keywords %>% unnest_tokens(word,keywords)
colnames(all_keyword_un) <-'keywords' # rename the column
# then you bind them to the full keywords, i.e. "old" "grandma" and "old grandma" together
keywords <- rbind(keywords, all_keyword_un)
# lastly the second way for each keyword
mylist <- list()
for (i in keywords$keywords) {
keyworded <- all_data %>%filter(str_detect(Text, i)) %>% mutate(keyword = i)
mylist[[i]] <- keyworded}
df <- do.call("rbind",mylist)%>%data.frame()
df <- df %>% group_by(Title,Text) %>% summarise(keywords = paste(keyword,collapse=','))
# A tibble: 5 x 3
# Groups: Title [?]
Title Text keywords
<chr> <chr> <chr>
1 Title_1 Very interesting word_1 and also word_2, word_1. word_1,word_2~
2 Title_2 hello word_1, and word_3. word_1,word_3~
3 Title_3 difficult! word_4b, and word_4a also word_4c word_4a,word_~
4 Title_4 A bit of word_1, some word_4a, and mostly word_3 word_1,word_3~
5 Title_6 Hey that sense feyenoord and are capable of providing word car are described. The text (800) uses at least one~ feyenoord,bmw~
,则会影响全局共享精度。我缺少每操作或每小数精度的东西吗?
编辑:我正在使用Python的get_context()
模块。
答案 0 :(得分:3)
有一个全局上下文,但是您不需要使用该上下文。您可以构造其他上下文并使用它们,或者在每个操作的基础上明确使用它们:
z = ctx.add(x, y)
b = a.ln(ctx)
或通过使用decimal.localcontext
设置临时本地上下文:
with decimal.localcontext(ctx):
z = x + y
b = a.ln()
第一个选项不太可能泄漏到您不希望执行的操作中,例如库例程或协程,而第二个选项则减少了在您需要执行操作时意外地将上下文从操作中移开的可能性。一堆具有相同上下文的操作。至少上下文不会泄漏到其他线程中,因为每个线程都有自己的当前上下文。