多维矩阵的最后一个元素

时间:2016-04-23 00:31:12

标签: python numpy multidimensional-array

我有一个多维矩阵,想要将最后一个元素设置为1.(例如po[-1]=1维度会有所不同,这就是我的问题。using namespace std; int main(){ std::string writeToFile; int file; char buf[128]; int nread; char pathNameTest[100]; pathNametest[0] = 'f'; pathNametest[0] = '\0'; cout << "Enter a file name without spaces: " endl; cin >> pathNameTest; file = open(pathNametest, O_RDONLY); if(file == -1) { cout << "Error" exit(0); } else { while(nread= read(file, buf, 10) > 0){ printf("%s",buf); } return 0; } 在这里不起作用。

1 个答案:

答案 0 :(得分:5)

我假设您正在使用NumPy,因为Python本身没有多维数组。

执行此操作的简单方法是使用数组的"flat"视图:

myarray.flat[-1] = 1
相关问题