小编Gun*_*tan的帖子

在void *函数中返回float

我正在学习指针的工作方式,但是我不理解此代码中的一件事。在void *函数中返回int就像一个超级按钮,但返回float却没有。

#include <stdio.h>

void* square (const void* num);

int main() {
  int x, sq_int;
  x = 6;
  sq_int = square(&x);
  printf("%d squared is %d\n", x, sq_int);

  return 0;
}

void* square (const void *num) {
  int result;
  result = (*(int *)num) * (*(int *)num);
  return result;
}
Run Code Online (Sandbox Code Playgroud)
#include <stdio.h>

void* square (const void* num);

int main() {
  float x, sq_int;
  x = 6;
  sq_int = square(&x);
  printf("%f squared is %f\n", x, sq_int);

  return 0;
}

void* square (const void …
Run Code Online (Sandbox Code Playgroud)

c pointers return function

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

奇怪的 scikit-learn Python 智能感知错误消息

最近,我正在使用 scikit-learn 包使用 Python 进行一些机器学习工作。\n我想使用 make_blobs() 函数,因此我开始编写代码,例如:

\n
X, y = make_blobs(n_samples=m, centers=2, n_features=2,  center_box=(80, 100))\n
Run Code Online (Sandbox Code Playgroud)\n

当然这很好。

\n

然而,在编写下一行代码时,我在 Visual Studio Code 中的 Intellisense(为了清楚起见,我只安装了适用于 Python 的 Microsoft 插件)开始在我之前提到的那一行上显示奇怪的错误。

\n

这是完整的错误消息:

\n
\n

类型为“tuple[Unknown | list[Unknown] | NDArray[float64], Unknown | list[Unknown] | NDArray[Any], ndarray[Any, dtype[float64]] | Any] | tuple[Unknown | list[Unknown] 的表达式] | NDArray[float64], Unknown | list[Unknown] | NDArray[Any]]" 无法分配给目标元组\n\xc2\xa0\xc2\xa0Type "tuple[Unknown | list[Unknown] | NDArray[float64] , Unknown | list[Unknown] | NDArray[Any], ndarray[Any, dtype[float64]] | Any]" 与目标元组不兼容\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 元素大小不合适; 预计 2 个,但收到 …

python intellisense scikit-learn visual-studio-code pyright

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