还在原地等你

文章 评论 浏览 29

还在原地等你 2025-02-20 22:12:41

怎么样:

library(ggplot2)
ages<- runif(100, 0, 22) #ages 0-22

#parameters for model
a1<-153
b1<-0.51
c1<-0.53

a2<-147
b2<-0.45
c2<-0.43

#generate length with error normally distributed 
length1 <- (a1*exp(-b1*exp(-c1*ages))) +rnorm(100, mean=0, sd=5)
length2 <- (a2*exp(-b2*exp(-c2*ages))) +rnorm(100, mean=0, sd=5)

df<-data.frame(Length=c(length1, length2), age=rep(ages, 2), location=c(rep(1,100), rep(2,100)))


gompertz.locs <- nls(formula = Length ~ 
                       as.numeric(location==1)*a1*exp(-b1*exp(-c1*age)) 
                     + as.numeric(location==2)*a2*exp(-b2*exp(-c2*age)),
                     data = df, 
                     start = list(a1=150,b1=0.5, c1=0.5,
                                  a2=150,b2=0.5, c2=0.5))

a <- coef(gompertz.locs)[c(1,4)]
b <- coef(gompertz.locs)[c(2,5)]
c <- coef(gompertz.locs)[c(3,6)]
df$fit <- a[df$location]*exp(-b[df$location]*exp(-c[df$location]*df$age))

ggplot(df, aes(x=age, y=Length, colour=as.factor(location))) + 
  geom_point() + 
  geom_line(aes(y=fit)) + 
  theme_classic() + 
  labs(colour="Location")

“”

在2022-07-06创建的

How about this:

library(ggplot2)
ages<- runif(100, 0, 22) #ages 0-22

#parameters for model
a1<-153
b1<-0.51
c1<-0.53

a2<-147
b2<-0.45
c2<-0.43

#generate length with error normally distributed 
length1 <- (a1*exp(-b1*exp(-c1*ages))) +rnorm(100, mean=0, sd=5)
length2 <- (a2*exp(-b2*exp(-c2*ages))) +rnorm(100, mean=0, sd=5)

df<-data.frame(Length=c(length1, length2), age=rep(ages, 2), location=c(rep(1,100), rep(2,100)))


gompertz.locs <- nls(formula = Length ~ 
                       as.numeric(location==1)*a1*exp(-b1*exp(-c1*age)) 
                     + as.numeric(location==2)*a2*exp(-b2*exp(-c2*age)),
                     data = df, 
                     start = list(a1=150,b1=0.5, c1=0.5,
                                  a2=150,b2=0.5, c2=0.5))

a <- coef(gompertz.locs)[c(1,4)]
b <- coef(gompertz.locs)[c(2,5)]
c <- coef(gompertz.locs)[c(3,6)]
df$fit <- a[df$location]*exp(-b[df$location]*exp(-c[df$location]*df$age))

ggplot(df, aes(x=age, y=Length, colour=as.factor(location))) + 
  geom_point() + 
  geom_line(aes(y=fit)) + 
  theme_classic() + 
  labs(colour="Location")

Created on 2022-07-06 by the reprex package (v2.0.1)

绘制具有分类变量和独立参数值的非线性(NLS)模型的单独曲线

还在原地等你 2025-02-20 20:34:18

我最终自己弄清楚了这个答案。我更改了格式化函数:

formatter: function(value, context) {
   return context.datasetIndex == 1 ? context.chart.data.labels[context.dataIndex] : ' ';
}

I ended up figuring out the answer to this myself. I changed the formatter function to this:

formatter: function(value, context) {
   return context.datasetIndex == 1 ? context.chart.data.labels[context.dataIndex] : ' ';
}

与Chart.js的堆叠条图表中仅在顶级栏上显示标签

还在原地等你 2025-02-20 18:06:58

Include Will Will检查以查看对象是否通过参考值相同。您可以通过使用一些检查条目的项目是否匹配。

console.log(data1.some(d => d.item === data2.item));

Include will check to see if the objects are the same by reference value. You can check if an entry's item is matching by using some.

console.log(data1.some(d => d.item === data2.item));

使用包括与数组的React

还在原地等你 2025-02-20 01:59:28

尝试:

WITH StartDates AS (
    SELECT CUSTOMERID, MIN(ASOFDATE) AS StartDate
    FROM #DATA
    WHERE FIRSTORDER = 1
    GROUP BY CUSTOMERID
)
DELETE D
FROM StartDates S
JOIN #DATA D
    ON D.CUSTOMERID = S.CUSTOMERID
    AND D.ASOFDATE < S.StartDate

请参阅

”选择每个客户的第一个订单参考日期,然后使用该信息选择要删除的记录。

Try:

WITH StartDates AS (
    SELECT CUSTOMERID, MIN(ASOFDATE) AS StartDate
    FROM #DATA
    WHERE FIRSTORDER = 1
    GROUP BY CUSTOMERID
)
DELETE D
FROM StartDates S
JOIN #DATA D
    ON D.CUSTOMERID = S.CUSTOMERID
    AND D.ASOFDATE < S.StartDate

See This db<>fiddle

The CTE (common table expression) first picks the FIRSTORDER reference date for each customer, and the main query then uses that information to select the records to be deleted.

需要删除在标志值之前存在的行

还在原地等你 2025-02-20 00:50:51

您可以执行以下操作:

import os

os.startfile("C:/Users/TestFile.txt", "print")

这将以动词为“打印”的默认开瓶机以其默认开启器启动文件,该文件将打印到您的默认打印机上。仅需要标准库随附的OS模块,

这仅在Windows上使用。因此,如果您希望它可以在其他操作系统上使用,则需要一种检测发送到哪个OS的OS。

You can do the following:

import os

os.startfile("C:/Users/TestFile.txt", "print")

This will start the file, in its default opener, with the verb 'print', which will print to your default printer.Only requires the os module which comes with the standard library

This only works on windows. So if you want it to work on other OS's you'll need a way to detect which OS the pdf is being sent to.

使用Python自动打印PDF

还在原地等你 2025-02-19 11:55:51

因为farm参数是一个休眠实体,所以它可能是hibernateProxy实例。您可能会认为,一个明确的例外表明,当您尝试访问type字段时,但是由于某种原因,在这种情况下,您会获得我上面发布的classcastException。如果您运行调试器并查看代码,您会发现分配的两面确实是完全相同的类,但是farm实例将是类型farm $ hibernateproxy $ ...如果确实是代理对象。

只是解开代理,您将避免此错误:-)

Because the farm parameter is a Hibernate entity, it may be a HibernateProxy instance. You would think that one would get an explicit exception stating that when you attempt to access the type field, but for some reason in this case you get the ClassCastException I posted above. If you run the debugger and take a look at the code you will see that both sides of the assignment are indeed the exact same class, but the farm instance will be of type Farm$HibernateProxy$... if indeed it is a proxy object.

Just unwrap the proxy and you will avoid this error :-)

为什么在两种类型相同的作业中,我会得到这个ClassCastException? (Groovy / Hibernate)

还在原地等你 2025-02-19 11:48:43

您可以在表单的Mousemove事件中注册。

this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);


private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    // e.Location.X;
    // e.Location.Y;
}

You could register on the MouseMove event of the Form.

this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);


private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    // e.Location.X;
    // e.Location.Y;
}

我如何相对跟踪光标的窗口c#c#

还在原地等你 2025-02-19 02:30:10

如果我正确理解,则需要适合“所有大写”等有条件的密码来减去点,同时也没有添加单个大写的积分。像目前一样,在您的示例中,“ ABC”将获得+5,因为一个小写,然后将所有小写的小写损失为5,而晚上为0,而不是-5。

我会在开始时将您的点递减条件放入单个IF语句中,然后将您的所有积分添加条件都放在if语句中,以在其他语句中:

if (userPassword.All(char.IsLower) ||
  userPassword.All(char.IsUpper) ||
  userPassword.All(char.IsDigit) ||
  userPassword.All(c => specialCharacters.Contains(c)) {
    points -= 5;
  } else {
      if (userPassword.Any(char.IsDigit)) {
        points += 5;
      }
      if (userPassword.Any(char.IsLower)) {
        points += 5;
      }
      if (userPassword.Any(char.IsUpper)) {
        points += 5;
      }
      if (userPassword.Any(c => specialCharacters.Contains(c))) {
        points += 5;
      }
    }

另外,如果您需要分开这些点赋予的条件以允许不同条件下的点扣除值的不同值,请使用更多的if if语句对不良情况使用:

if (userPassword.All(char.IsLower) || userPassword.All(char.IsUpper)) {
  points -= 5;
} else if (userPassword.All(char.IsDigit)) {
  points -= 5;
} else if (userPassword.All(c => specialCharacters.Contains(c))) {
  points -= 5;
} else {
  if (userPassword.Any(char.IsDigit)) {
    points += 5;
  }
  if (userPassword.Any(char.IsLower)) {
    points += 5;
  }
  if (userPassword.Any(char.IsUpper)) {
    points += 5;
  }
  if (userPassword.Any(c => specialCharacters.Contains(c))) {
    points += 5;
  }
}

If I'm understanding correctly, you want passwords which fit the "all uppercase," et cetera conditionals to subtract points while also NOT adding points for having a single uppercase. Like currently, "abc" in your example would receive +5 for having one lowercase, then would lose 5 for having all lowercase, evening out to 0 rather than -5.

I would put your point-deducting conditionals into a single if statement at the beginning, then put all of your point-adding conditionals into if statements within an else statement:

if (userPassword.All(char.IsLower) ||
  userPassword.All(char.IsUpper) ||
  userPassword.All(char.IsDigit) ||
  userPassword.All(c => specialCharacters.Contains(c)) {
    points -= 5;
  } else {
      if (userPassword.Any(char.IsDigit)) {
        points += 5;
      }
      if (userPassword.Any(char.IsLower)) {
        points += 5;
      }
      if (userPassword.Any(char.IsUpper)) {
        points += 5;
      }
      if (userPassword.Any(c => specialCharacters.Contains(c))) {
        points += 5;
      }
    }

Alternatively, if you needed those point-deducting conditionals to be separated to allow for different values of point deductions for different conditions, just use more else if statements for the bad ones:

if (userPassword.All(char.IsLower) || userPassword.All(char.IsUpper)) {
  points -= 5;
} else if (userPassword.All(char.IsDigit)) {
  points -= 5;
} else if (userPassword.All(c => specialCharacters.Contains(c))) {
  points -= 5;
} else {
  if (userPassword.Any(char.IsDigit)) {
    points += 5;
  }
  if (userPassword.Any(char.IsLower)) {
    points += 5;
  }
  if (userPassword.Any(char.IsUpper)) {
    points += 5;
  }
  if (userPassword.Any(c => specialCharacters.Contains(c))) {
    points += 5;
  }
}

如何使我的if陈述较少矛盾?

还在原地等你 2025-02-18 06:21:54

尝试:

s = "there is wall E on the way"
spans = [(0,5), (9,13), (16,18)]


def solution(sentence, location):
    res = list(sentence)
    for start, end in location:
        res[start], res[end] = "<span>" + res[start], "</span>" + res[end]
    return "".join(res)


for s, l in [
    ["there is wall E on the way", [(0,5), (9,13), (16,18)]],
    ["there is wall E on the way", [(0,5), (16,18)]],
    ["there is wall E on the way", [(0,5), (16,22)]],
    ["there is wall E on the way", [(0,11), (16,22)]],
]:
    print(solution(s, l))

输出:

<span>there</span> is <span>wall</span> E <span>on</span> the way
<span>there</span> is wall E <span>on</span> the way
<span>there</span> is wall E <span>on the</span> way
<span>there is wa</span>ll E <span>on the</span> way

try it:

s = "there is wall E on the way"
spans = [(0,5), (9,13), (16,18)]


def solution(sentence, location):
    res = list(sentence)
    for start, end in location:
        res[start], res[end] = "<span>" + res[start], "</span>" + res[end]
    return "".join(res)


for s, l in [
    ["there is wall E on the way", [(0,5), (9,13), (16,18)]],
    ["there is wall E on the way", [(0,5), (16,18)]],
    ["there is wall E on the way", [(0,5), (16,22)]],
    ["there is wall E on the way", [(0,11), (16,22)]],
]:
    print(solution(s, l))

OUTPUT:

<span>there</span> is <span>wall</span> E <span>on</span> the way
<span>there</span> is wall E <span>on</span> the way
<span>there</span> is wall E <span>on the</span> way
<span>there is wa</span>ll E <span>on the</span> way

如何将标签添加到字符串中的子字符串跨越?

还在原地等你 2025-02-17 06:41:20

您几乎拥有它的

func buildObject<R: MyProtocol>(objectIn: MyProtocol, returnType: R.Type) -> R {
    let returnObject = returnType.init(id: objectIn.id, name: objectIn.name)
    return returnObject
}

关键观察:在任何时候我们都需要objectin的具体类型,因此只需要协议类型即可。

You almost had it

func buildObject<R: MyProtocol>(objectIn: MyProtocol, returnType: R.Type) -> R {
    let returnObject = returnType.init(id: objectIn.id, name: objectIn.name)
    return returnObject
}

the key observation: at no point do we need the concrete type of objectIn, so just require the protocol type.

Swift Generics/不透明类型:尝试使用协议一致性在通用函数中的类型之间转换

还在原地等你 2025-02-16 22:24:14

ExchangeFilterFunction中,您可以访问该请求。您可以使用一些标识符“装饰”您的请求,然后使用它来解决客户端。

  1. 您可以添加一些请求标题来识别客户端。
  2. 要保持内部,您可以使用WebClient的请求属性,然后从请求对象读取它
webClient.get()
       .uri("...")
       .attributes((attributes) -> attributes.put("internal_client_id", clientId))

In the ExchangeFilterFunction you have access to the request. You could "decorate" your request with some identifier and then use it to resolve the client.

  1. You could add some request header to identify the client.
  2. To keep it internal, you could use request attributes of the WebClient and then read it from the request object
webClient.get()
       .uri("...")
       .attributes((attributes) -> attributes.put("internal_client_id", clientId))

使用Mono Zip识别哪些请求失败时,请在网络上获取请求主体

还在原地等你 2025-02-16 20:44:15

DefaultDict是为此设计的。

import collections
mydict = collections.defaultdict(int)

range_val = [str(i).zfill(2) for i in range(100)]

for v in range_val:
   mydict[v] = mydict[v] + 1

defaultdict was designed for this.

import collections
mydict = collections.defaultdict(int)

range_val = [str(i).zfill(2) for i in range(100)]

for v in range_val:
   mydict[v] = mydict[v] + 1

如果我需要在右侧引用字典,如何将值分配给字典?

还在原地等你 2025-02-16 18:28:59

可以使用扫描集%1 [+ - /*]将在一组运算符中扫描一个字符。
如果字符不在集合中,scanf将返回0。清洁输入流,然后重试。

#include <stdio.h>
#include <stdlib.h>

int main ( void) {
    char op[2] = "";
    int result = 1;

    printf ("Enter an operator!\n");
    do {
        if ( result != 1) {
            printf ("Enter an operator!\n");
        }
        result = scanf ( "%1[+-/*]", op);
        if ( result == EOF) {
            fprintf ( stderr, "EOF\n");
            return 1;
        }
        int clean = 0;
        while ( ( clean = fgetc ( stdin)) != '\n') { // clean input stream
            if ( clean == EOF) {
                fprintf ( stderr, "EOF\n");
                return 1;
            }
        }
    } while ( result != 1);

    printf ( "operator %s\n", op);

    return 0;
}

A scan set could be used %1[+-/*] will scan one character in the set of operators.
If the character is not in the set, scanf will return 0. Clean the input stream and try again.

#include <stdio.h>
#include <stdlib.h>

int main ( void) {
    char op[2] = "";
    int result = 1;

    printf ("Enter an operator!\n");
    do {
        if ( result != 1) {
            printf ("Enter an operator!\n");
        }
        result = scanf ( "%1[+-/*]", op);
        if ( result == EOF) {
            fprintf ( stderr, "EOF\n");
            return 1;
        }
        int clean = 0;
        while ( ( clean = fgetc ( stdin)) != '\n') { // clean input stream
            if ( clean == EOF) {
                fprintf ( stderr, "EOF\n");
                return 1;
            }
        }
    } while ( result != 1);

    printf ( "operator %s\n", op);

    return 0;
}

首先,SCANF为下一个scanfs获得其他Chrachter

还在原地等你 2025-02-16 15:47:53

正如@galik评论。这是基于意见的。

但是我们可以指出的是:

  • 在C ++中,我们不应将原始指针用于拥有的内存
  • newdelete应避免使用
  • C风格数组,应避免
  • 阅读到> data()将起作用,但不是很好(我的看法)。无论如何,比使用新的并创建内存泄漏更好。

您可以,在简单的中,循环从文件中读取一个字节,然后将每个字节添加到std :: string带有+= 。但这也很笨拙。

最好的是,如果允许您使用C ++语言和库。

顺便提一句。 std :: String也是“变量大小数组”

建议:使用第二个解决方案

As @Galik commented. This is opinion based.

But what we can state is:

  • In C++ we should not use raw pointers for owned memory
  • new and delete should be avoided
  • C-Style arrays should be avoided
  • Reading into data() will work, but is not that nice (my opinion). Anyway, better than using new and creating a memory leak.

You could, in a simple for loop read one byte after the other from the file and then add each byte to the std::string with +=. But this is also very clumsy.

Best would be, if you were allowed to use C++ language and libraries.

BTW. std::string is also a "variable-sized array"

Recommendation: Go with your second solution

这是在C&#x2B;&#x2B;中读入字符串的好习惯?

还在原地等你 2025-02-16 13:40:09

只需添加行shift = shift *(len(msg)// len(shift) + 1)在函数开始时,请重复shift,直到比它更长msg(例如,这一行转动数学MATHMATH

import string

def vigenere_cipher(msg, shift):
    shift = shift * (len(msg) // len(shift) + 1)
    encrypted = ''
    for i,j in zip(msg,shift):
        new_index = (string.ascii_uppercase.index(i) + string.ascii_uppercase.index(j)) % 26
        encrypted += string.ascii_uppercase[new_index]
    return encrypted

    
print(vigenere_cipher('PYTHON', 'MATH'))

输出:bymoan

Just add the line shift = shift * (len(msg) // len(shift) + 1) at the start of the function so shift is repeated until it's longer than msg (e.g. this line turns MATH into MATHMATH)

import string

def vigenere_cipher(msg, shift):
    shift = shift * (len(msg) // len(shift) + 1)
    encrypted = ''
    for i,j in zip(msg,shift):
        new_index = (string.ascii_uppercase.index(i) + string.ascii_uppercase.index(j)) % 26
        encrypted += string.ascii_uppercase[new_index]
    return encrypted

    
print(vigenere_cipher('PYTHON', 'MATH'))

Output: BYMOAN

如何在单词开头重新开始?

更多

推荐作者

眼泪淡了忧伤

文章 0 评论 0

corot39

文章 0 评论 0

守护在此方

文章 0 评论 0

github_3h15MP3i7

文章 0 评论 0

相思故

文章 0 评论 0

滥情空心

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文