小编Abd*_*heb的帖子

Python numpy.corrcoef()RuntimeWarning:在true_divide中遇到无效值c/= stddev [:,None]

看来,corrcoefnumpy抛出RuntimeWarning当一个恒定的列表传递给corrcoef()函数,例如下面的代码抛出一个警告:

import numpy as np
X = [1.0, 2.0, 3.0, 4.0]
Y = [2, 2, 2, 2]
print(np.corrcoef(X, Y)[0, 1])
Run Code Online (Sandbox Code Playgroud)

警告 :

/usr/local/lib/python3.6/site-packages/numpy/lib/function_base.py:3003: RuntimeWarning: invalid value encountered in true_divide
  c /= stddev[:, None]
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释为什么当其中一个列表是常量时抛出此错误,以及如何在将常量列表传递给函数时防止此错误.

python numpy correlation

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

立即从流中提取 Java zip 文件,无需使用 byte[]

我想将多个文件压缩成一个zip文件,我正在处理大文件,然后将它们下载到客户端,目前我正在使用这个:

@RequestMapping(value = "/download", method = RequestMethod.GET, produces = "application/zip")
public ResponseEntity <StreamingResponseBody> getFile() throws Exception {
    File zippedFile = new File("test.zip");
    FileOutputStream fos = new FileOutputStream(zippedFile);
    ZipOutputStream zos = new ZipOutputStream(fos);
    InputStream[] streams = getStreamsFromAzure();
    for (InputStream stream: streams) {
        addToZipFile(zos, stream);
    }
    final InputStream fecFile = new FileInputStream(zippedFile);
    Long fileLength = zippedFile.length();
    StreamingResponseBody stream = outputStream - >
        readAndWrite(fecFile, outputStream);

    return ResponseEntity.ok()
        .header(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION)
        .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + "download.zip")
        .contentLength(fileLength)
        .contentType(MediaType.parseMediaType("application/zip"))
        .body(stream);
}

private void addToZipFile(ZipOutputStream zos, InputStream fis) …
Run Code Online (Sandbox Code Playgroud)

java zip spring download stream

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

PySpark 在初始新值后的 24 小时窗口内删除重复消息

我有一个带有状态(整数)和时间戳的数据框。由于我收到很多“重复”状态消息,因此我想通过删除“新”状态后 24 小时窗口内重复先前状态的任何行来减少数据帧,这意味着:

  • 第一个 24 小时窗口以特定状态的第一条消息开始。
  • 该状态的下一个 24 小时窗口从第一个 24 小时窗口之后出现的下一条消息开始(窗口不是连续的)。

举个例子:

data = [(10, datetime.datetime.strptime("2022-01-01 00:00:00", "%Y-%m-%d %H:%M:%S")),
        (10, datetime.datetime.strptime("2022-01-01 04:00:00", "%Y-%m-%d %H:%M:%S")),
        (10, datetime.datetime.strptime("2022-01-01 23:00:00", "%Y-%m-%d %H:%M:%S")),
        (10, datetime.datetime.strptime("2022-01-02 05:00:00", "%Y-%m-%d %H:%M:%S")),
        (10, datetime.datetime.strptime("2022-01-02 06:00:00", "%Y-%m-%d %H:%M:%S")),

        (20, datetime.datetime.strptime("2022-01-01 03:00:00", "%Y-%m-%d %H:%M:%S"))
      ]

myschema = StructType(
    [
        StructField("status", IntegerType()),
        StructField("ts", TimestampType())
    ]
)
df = spark.createDataFrame(data=data, schema=myschema)
Run Code Online (Sandbox Code Playgroud)
  • 第一个 24 小时状态窗口10是从2022-01-01 00:00:002022-01-02 00:00:00
  • 第二个 24 小时状态窗口10是从2022-01-02 05:00:002022-01-03 …

python apache-spark apache-spark-sql pyspark

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

Android:Espresso,层次结构中找不到匹配的视图

我正在测试我的活动中的片段的启动,所以在执行点击按钮以启动片段之后,我测试了已启动片段内的视图上现有的文本,但是测试失败,即使该片段是在我的手机上启动,甚至在View Hierarchy中显示文本存在:

View Hierarchy:

+--------->AppCompatTextView{id=2131886318, res-name=text3_textView, visibility=VISIBLE, width=768, height=68, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=695.0, text=Pour finaliser votre inscription nous avons besion
d'une photo de profil, input-type=0, ime-target=false, has-links=false}
Run Code Online (Sandbox Code Playgroud)

测试失败了:

onView(withText("photo de profil")).check(matches(isDisplayed()));
Run Code Online (Sandbox Code Playgroud)

我想知道为什么espresso失败了这个测试,是因为它不等待片段的发布?

顺便说一句,我关闭了动画.

testing android android-espresso

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

Angular ngx-bootstrap折叠不是动画的

我正在使用angular 5和ngx-bootstrap,所以当我尝试添加一个collpase时,通过跟随折叠文档,我得到了一个工作示例但没有动画(折叠的分散并立即显示没有效果).

那么有没有办法展示动画?

animation collapse ngx-bootstrap angular angular5

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

Java 将大文件的 MultipartFile 转换为 File

我使用以下方法将 MultipartFile 转换为文件:

public File convert(MultipartFile file) throws IOException {
        File convFile = new File(file.getOriginalFilename());
        convFile.createNewFile();
        FileOutputStream fos = new FileOutputStream(convFile);
        fos.write(file.getBytes());
        fos.close();
        return convFile;
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但对于大文件我得到了这个例外:

java.lang.OutOfMemoryError:Java堆空间

我添加了更多堆,但仍然出现错误。

那么是否有一种编程方法可以解决这个问题,可能在转换时将多部分文件分割成更小的块,但我不确定如何编码。

任何帮助或建议将不胜感激。

java spring multipart

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

带复选框的角材质垫树全选

我正在使用带有复选框的 Tree,并且我想添加一个按钮来检查所有复选框,我尝试了不同的方法但没有好处,我能够实现的最好的事情是:

  selectAllFiscal() {
    this.rootItems.forEach(node => {
      this.todoItemSelectionToggle(node);
    });
  }
Run Code Online (Sandbox Code Playgroud)

rootItems 是一个根节点数组。

我可以看到迭代时选择了节点checklistSelection.selected,但是浏览器中没有选择复选框,任何人都可以指出问题,谢谢。

checkbox tree angular-material angular

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

React Native 升级失败:致命:工作树“。” 已经存在

我尝试使用这些说明将 React Native 版本从 0.41 升级到 0.44 ,但出现此错误:

error Command failed.
Exit code: 128
Command: git
Arguments: clone https://github.com/lwansbrough/react-native-camera.git /Users/abdelnacer/Library/Caches/Yarn/v1/.tmp/264e7f98ae7b8a32797877705f218964
Directory: /Users/abdelnacer/work/react/DuluxTradePoints
Output:
fatal: working tree '.' already exists.
git-upgrade ERR! An error occurred during upgrade: 
git-upgrade ERR! Error: Command 'yarn add react-native@0.42.0' exited with code 1:
stderr: undefinederror Command failed.
Exit code: 128
Command: git
Arguments: clone https://github.com/lwansbrough/react-native-camera.git /Users/abdelnacer/Library/Caches/Yarn/v1/.tmp/264e7f98ae7b8a32797877705f218964
Directory: /Users/abdelnacer/work/react/DuluxTradePoints
Output:
fatal: working tree '.' already exists.

stdout: yarn add v0.24.5
[1/4] Resolving packages...
info Visit …
Run Code Online (Sandbox Code Playgroud)

upgrade react-native

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

Android Camera2:无法用前置摄像头拍照

我目前正在使用android-Camera2Basic,这个样本设计用后置摄像头拍照,它工作正常,但当我改变这一:

if (facing != null && facing != CameraCharacteristics.LENS_FACING_FRONT)
Run Code Online (Sandbox Code Playgroud)

预览显示了预期的相机,但单击图片按钮时不拍照.

为什么发生这种情况我需要改变别的东西?

android android-camera

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

从导航堆栈中反应本机路由器磁通重置场景

我有一个场景(让所谓的sceneA其中一个)大量数据的列表视图中呈现,所以导航到另一个场景后,用户界面变得非常缓慢和laggy因为sceneA通过调用仍然在导航堆栈中,我试图解决这个问题:Actions.sceneA({type: "reset"})里面componentWillUnmount()sceneA,但这似乎没有工作,因为componentWillUnmount()导航到另一个场景后从未调用,所以有没有办法在应用程序内导航时重置以前的场景?

navigation react-native react-native-router-flux

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