Hot answers tagged

5

You should choose better functions names, function does not give any indication what the purpose of the function is. In addition, a docstring comment can be used to give a short description. But actually there is no need for a custom function because numpy.sign already provides the exact functionality: Returns an element-wise indication of the sign of a ...


3

The real power of OOP is not that you can use classes as namespaces to bundle functions that belong together. The main power is polymorphism, meaning that you can inherit from classes and use subclasses interchangeably with their parent classes. This means that you want to be able to do something like this: class UnitaryMatrix(Matrix): ... a = Matrix(......


2

I would make a few suggestions, rather than just saving the input string it would be better, as you suggest, to save the output of the get_rows function in memory, so you don't have to recreate it every time. Similarly when you want an individual row or column, it seems inefficient to gather all the rows, (and then all the columns) just to reject all but one ...


1

I think it the following is a good approach: //use lowercase on non constant values void print_symmetric_packed_matrix(double* compact_matrix, int n) { const int entries = N*N; for (int i = 0; i < entries;) { //i++ here avoids i != 0 each iteration printf("%f ", compact_matrix[i++]); if (i % N == 0) printf(&...


Only top voted, non community-wiki answers of a minimum length are eligible