-New: Add function print_numpy_array to SparseMatrix and LinearAlgebra::Vector to
-output the object in a format readable with numpy.loadtxt.
+New: Add functions SparseMatrix::print_as_numpy_arrays() and
+LinearAlgebra::Vector::print_as_numpy_array() to output the
+object in a format readable with numpy.loadtxt.
<br>
(Bruno Turcksin, 2019/06/02)
* </code>
*/
void
- print_numpy_array(std::ostream & out,
- const unsigned int precision = 9) const;
+ print_as_numpy_array(std::ostream & out,
+ const unsigned int precision = 9) const;
/**
* Write the vector en bloc to a file. This is done in a binary mode, so
template <typename Number>
void
- Vector<Number>::print_numpy_array(std::ostream & out,
- const unsigned int precision) const
+ Vector<Number>::print_as_numpy_array(std::ostream & out,
+ const unsigned int precision) const
{
AssertThrow(out, ExcIO());
boost::io::ios_flags_saver restore_flags(out);
print_pattern(std::ostream &out, const double threshold = 0.) const;
/**
- * Print the vector to the output stream @p out in a format that can be
+ * Print the matrix to the output stream @p out in a format that can be
* read by numpy::readtxt(). To load the matrix in python just do
* <code>
* [data, row, column] = numpy.loadtxt('my_matrix.txt')
* </code>
*/
void
- print_numpy_array(std::ostream &out, const unsigned int precision = 9) const;
+ print_as_numpy_arrays(std::ostream & out,
+ const unsigned int precision = 9) const;
/**
* Write the data of this object en bloc to a file. This is done in a binary
template <typename number>
void
-SparseMatrix<number>::print_numpy_array(std::ostream & out,
- const unsigned int precision) const
+SparseMatrix<number>::print_as_numpy_arrays(std::ostream & out,
+ const unsigned int precision) const
{
AssertThrow(out, ExcIO());
boost::io::ios_flags_saver restore_flags(out);
// ---------------------------------------------------------------------
-// Check that print_numpy_array works
+// Check that print_as_numpy_array works
#include <deal.II/lac/la_vector.h>
for (unsigned int i = 0; i < size; ++i)
vec(i) = static_cast<number>(i);
- vec.print_numpy_array(deallog.get_file_stream());
+ vec.print_as_numpy_array(deallog.get_file_stream());
}
// ---------------------------------------------------------------------
-// Check that print_numpy_array works
+// Check that print_as_numpy_arrays works
#include <deal.II/lac/sparse_matrix.h>
#include <deal.II/lac/sparsity_pattern.h>
for (unsigned int i = 0; i < n; ++i)
for (unsigned int j = 0; j < n; ++j)
A.set(i, j, static_cast<number>(i + j));
- A.print_numpy_array(deallog.get_file_stream());
+ A.print_as_numpy_arrays(deallog.get_file_stream());
}