我有一个numpy2D数组,其形状(4898, )是每行中的元素用分号分隔,但仍存储在单列而不是多列中(期望的结果)。如何在2D数组的每个数组中每次出现分号时创建拆分。我已经编写了以下Python脚本来这样做,但是会引发错误。
stochastic_gradient_descent_winequality.py
import numpy
import pandas
if __name__ == '__main__' :
with open('winequality-white.csv', 'r') as f_0 :
with open('winequality-white-updated.csv', 'w') as f_1 :
f_0.next()
for line in f_0 :
f_1.write(line)
wine_data = pandas.read_csv('winequality-white-updated.csv', sep = ',', header = None)
wine_data_ = wine_data
wine_data = numpy.array([x.split(';') for x in wine_data_], dtype = numpy.float)
print (numpy.shape(wine_data))
Run Code Online (Sandbox Code Playgroud)
失误
Traceback (most recent call last):
File "stochastic_gradient_descent_winequality.py", line 16, in <module>
wine_data = numpy.array([x.split(';') for x in wine_data_], …Run Code Online (Sandbox Code Playgroud) 我是并行编程领域的新手,所以我决定摆弄pthread_join()子程序.我想出了以下代码来计算*X + Y,其中a是标量,X,Y是某种大小的向量.
这是我写的:
#include <pthread.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 4
#define VECTOR_SIZE 65
struct DAXPYdata
{
/* data */
long a;
long X[VECTOR_SIZE];
long Y[VECTOR_SIZE];
};
struct DAXPYdata daxpystr;
void *calcDAXPY(void *);
int main(int argc, char *argv[])
{
int vec_index;
/*Initialize vectors X and Y an scalar a*/
daxpystr.a = 57;
for(vec_index = 0 ; vec_index < 65 ; vec_index++){
daxpystr.X[vec_index] = vec_index + 1;
daxpystr.Y[vec_index] = vec_index + 2;
}
pthread_t call_thread[NUM_THREADS];
pthread_attr_t attr; …Run Code Online (Sandbox Code Playgroud) 我试图从文本文件中读取一行,但程序仍然返回一个错误,指出无法找到该文件的名称.关于如何解决问题的任何想法.
源代码:
import java.io.FileReader;
import java.io.BufferedReader;
public class Cipher {
public String file_name;
public Cipher(){
file_name = "/Users/SubrataMohanty/IdeaProjects/CaesarCipher/src/cipher_text.txt";
}
public static void main(String[] args) {
BufferedReader br = null;
FileReader fr = null;
Cipher cipher_1 = new Cipher();
fr = new FileReader(cipher_1.file_name);
br = new BufferedReader(fr);
String current_line;
while ((current_line = br.readLine()) != null){
System.out.println(current_line);
}
}
}
Run Code Online (Sandbox Code Playgroud)
经过调试,这就是我得到的,
Error:(25, 14) java: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
Error:(30, 43) java: unreported exception java.io.IOException; must …Run Code Online (Sandbox Code Playgroud)