mirror of
https://git.gfz-potsdam.de/naaice/poet.git
synced 2025-12-16 04:48:23 +01:00
change dimensions in vector_to_numpy_array
This commit is contained in:
parent
4169cf8a20
commit
80165db6d0
@ -92,20 +92,23 @@ int Python_Keras_load_model(std::string model, std::string model_reactive,
|
||||
* @return Numpy representation of the input vector
|
||||
*/
|
||||
PyObject* vector_to_numpy_array(const std::vector<std::vector<double>>& field) {
|
||||
npy_intp dims[2] = {static_cast<npy_intp>(field[0].size()),
|
||||
static_cast<npy_intp>(field.size())};
|
||||
npy_intp dims[2] = {static_cast<npy_intp>(field.size()), // Zeilenanzahl
|
||||
static_cast<npy_intp>(field[0].size())}; // Spaltenanzahl
|
||||
|
||||
PyObject* np_array = PyArray_SimpleNew(2, dims, NPY_FLOAT64);
|
||||
double* data = static_cast<double*>(PyArray_DATA((PyArrayObject*)np_array));
|
||||
// write field data to numpy array
|
||||
|
||||
// Schreibe die Daten in das Numpy-Array (korrekte Reihenfolge)
|
||||
for (size_t i = 0; i < field.size(); ++i) {
|
||||
for (size_t j = 0; j < field[i].size(); ++j) {
|
||||
data[j * field.size() + i] = field[i][j];
|
||||
data[i * field[0].size() + j] = field[i][j]; // Korrekte Indizes
|
||||
}
|
||||
}
|
||||
|
||||
return np_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a Pyton matrix object to a std::vector vector
|
||||
* @param py_matrix Pyobject that must be a 2D matrix
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user