我正在尝试填充 NumPy 数组的 NumPy 数组。每次我完成循环的迭代时,我都会创建要添加的数组。然后我想将该数组附加到另一个数组的末尾。例如:
first iteration
np.append([], [1, 2]) => [[1, 2]]
next iteration
np.append([[1, 2]], [3, 4]) => [[1, 2], [3, 4]]
next iteration
np.append([[1, 2], [3, 4]], [5, 6]) => [[1, 2], [3, 4], [5, 6]]
etc.
Run Code Online (Sandbox Code Playgroud)
我试过使用 np.append 但这返回一个一维数组,即
[1, 2, 3, 4, 5, 6]
Run Code Online (Sandbox Code Playgroud) 我正在为我的Data Structures类开发一个哈希表实验室.当我在insert函数中使用push_back()函数时,我一直在遇到一个设定的错误.但是,我不确定导致此错误的原因.
using namespace std;
HashTable::HashTable(int buckets) {
this->buckets = buckets;
vector<Entry>* table = new vector<Entry>[buckets];
}
Entry HashTable::insert(GameBoard board, int number) {
int index = compress(board.hashCode());
Entry entry = Entry(board, number);
table[index].push_back(entry);
return entry;
}
int HashTable::compress(int hashCode) {
return (hashCode % buckets);
}
Entry::Entry(GameBoard board, int value) {
this->board = board;
this->value = value;
}
int GameBoard::hashCode() {
int hashVal = 0;
for (int r = 0; r < DIMENSION; r++) {
for (int c = 0; c …Run Code Online (Sandbox Code Playgroud)