小编For*_*Bru的帖子

在C++中转置矩阵

我正在编写一个程序来使用分配的内存来转置给定的矩阵.该函数与方矩阵NxN(rows == cols)完美配合,但它与MxN矩阵(rows!= cols)崩溃.请帮忙

void transpose(int **matrix, int *row, int *col)
{
    // dynamically allocate an array
    int **result;
    result = new int *[*col]; //creates a new array of pointers to int objects
    // check for error
    if (result == NULL)
    {
        cout << "Error allocating array";
        exit(1);
    }
    for (int count = 0; count < *col; count++)
    {
        *(result + count) = new int[*row];
    }

    // transposing
    for (int i = 0; i<*row; i++)
    {
       for (int j = …
Run Code Online (Sandbox Code Playgroud)

c++ transpose matrix

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

如何在C++ 11中初始化uint64_t

uint64_t x(1 << 35)给出输出0和警告.初始化这么大的值最合适的是什么?

c++ c++11

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

Pandas,如何为所有以数字开头的列名添加前缀?

我有一个包含很多列的数据集,超过 400,其中一些列名的开头有数字,这是列名的部分列表:

nextday_open
nextday_movement
nextday_movement_direction
nextday_movement_amount
nextday_daytime_movement
nextday_daytime_direction
overnight_movement
overnight_direction
5days_running_std
5days_running_var
5days_diff_std
5days_running_med_diff
Run Code Online (Sandbox Code Playgroud)

如何向所有以数字开头的列附加前缀?它应该是这样的:

nextday_open
nextday_movement
nextday_movement_direction
nextday_movement_amount
nextday_daytime_movement
nextday_daytime_direction
overnight_movement
overnight_direction
col_5days_running_std
col_5days_running_var
col_5days_diff_std
col_5days_running_med_diff
Run Code Online (Sandbox Code Playgroud)

由于列太多,我无法单独重命名它们。

python pandas

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

Python导入与直接执行

#conf.py

def init():
    global mylist   
    mylist=[]


#change.py

import conf

def change():
    if __name__ == "__main__":
        print('Direct')
        conf.mylist.append('Directly executed')
        print(conf.mylist)
    else:
        conf.mylist.append('It was imported') 


#exec.py

import conf
import change

conf.init()  
change.change()

print (conf.mylist)
Run Code Online (Sandbox Code Playgroud)

运行exec.py时,结果是我的预期,直接运行change.py时,我没有得到任何输出(没有Direct,没有conf.mylist)

python python-import

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

从“const char*”到“char*”的无效转换

#include <stdio.h>
#include <string.h>
#include <conio.h>
#define SIZE 20

int main( void )
{
    int n; //number of characters to be compared
    char s1[ SIZE ], s2[ SIZE ];
    char *results_word;

    printf( "Enter two strings: " );
    gets( s1 );
    gets( s2 );
    printf( "\nEnter the number of characters to be compared: " );
    scanf( "%d", &n );
Run Code Online (Sandbox Code Playgroud)

问题从这里开始

    results_word = 
                 strncmp( s1, s2, n ) > 0 ? " greater than " : 
                 strncmp( s1, s2, n ) == …
Run Code Online (Sandbox Code Playgroud)

c++ string strcmp

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

python为什么如果零,当零= 0时打印('真'),它什么都不打印?

在python中为什么

zero = 0
one = 1
if zero:
  print('True') # this print nothing
if one:
  print('True') # this print True
Run Code Online (Sandbox Code Playgroud)

我想什么时候zero = 0,这应该是正确的。应该给我True,但为什么什么都不给?如果这是正确的,为什么什么时候if one,它给了我True

python python-3.x

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

C++ 上的数学输出(对照其他语言进行检查)

我用 C++ 写这个:

int main()
{
    cout<<"print "<< int(((float(979430543) - float(800445804))/2.0)+.5);
}

for output: 89492352
Run Code Online (Sandbox Code Playgroud)

并检查 Julia 语言:

print(Int64(((Float64(979430543) - Float64(800445804))/2.0)+.5))
89492370
Run Code Online (Sandbox Code Playgroud)

结果之间的差异是 18 - 我错过了什么?

c++ julia

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

如何从C#程序中检索WMI数据(例如UUID)?

要检索系统的UUID,我们可以选择WMIC命令行实用程序

wmic csproduct get uuid
Run Code Online (Sandbox Code Playgroud)

如何使用C或C#程序或.dll从系统中检索相同的uuid?

c c# wmi system wmic

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

为什么我的字符串长度与我选择的不同?

我想用数字创建一个字符串。所以我将字符串数组的长度定义为 10,但是当我在控制台中启动程序时是 11 个字符。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define N 10

using namespace std;

int main()
{
    srand(time(0));
    int numArr[N];

    for(int i = 0; i < N; i++)
        numArr[i] = rand() % 26 + 97;

    for(int i = 0; i < N; i++)
        std::cout << numArr[i] << " ";
    std::cout << std::endl;

    char str[N] = "";

    for(int i = 0; i < N; i++)
        str[i] = numArr[i];

    std::cout << str << endl;
    std::cout << strlen(str);
    return …
Run Code Online (Sandbox Code Playgroud)

c++

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

VSCode (tkinter) 中根本不显示窗口

我正在 Visual Studio Code 中尝试 tkinter,但没有显示此代码的窗口(只是测试):

from tkinter import * 
Tk()
Run Code Online (Sandbox Code Playgroud)

我是否错过了任何安装?

python tkinter python-3.x

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

标签 统计

c++ ×5

python ×4

python-3.x ×2

c ×1

c# ×1

c++11 ×1

julia ×1

matrix ×1

pandas ×1

python-import ×1

strcmp ×1

string ×1

system ×1

tkinter ×1

transpose ×1

wmi ×1

wmic ×1