Question: After being a MATLAB user for many years, I am now migrating to python.

I try to find a concise manner to simply rewrite the following MATLAB code in python:

```
s = sum(Mtx);
newMtx = Mtx(:, s>0);

```

where Mtx is a 2D sparse matrix

My python solution is:

```
s = Mtx.sum(0)
newMtx = Mtx[:, np.where((s>0).flat)[0]] # taking the columns with nonzero indices

```

where Mtx is a 2D CSC sparse matrix

The python code is not as readable / elegant as in matlab.. any idea how to write it more elegantly?

Thanks!

Answer: 
Not sure this is what you want, it is ugly, but it works :)
You can wrap the type into a template class,

```
template <typename T, int N> // N is used for tagging
struct strong_typedef
{
    using strong_type = strong_typedef<T,N>; // typedef for the strong type
    using type = T; // the wrapped type
    T value; // the  wrapped value

    strong_typedef(T val): value(val){}; // constructor
    strong_typedef(){value={};}; // default, zero-initialization

    // operator overloading, basic example: 
    strong_type operator+(const strong_type& rhs) const
    {
        return value + rhs.value;
    }

    // display it
    friend ostream& operator<<(ostream & lhs, const strong_typedef& rhs)
    {
        lhs << rhs.value;
        return lhs;
    }
};

```

then use it as

```
// these are all different types
strong_typedef<double, 0> x = 1.1; 
strong_typedef<double, 1> y = 2.2;
strong_typedef<double, 2> z = 3.3;

std::cout << x + x << std::endl; // outputs 2.2, can add x and x
// cout << x + y << endl; // compile-time ERROR, different types

```

`x`, `y` and `z` are 3 different types now, because of the different `N`-s used in the template. You can access the type and value using the fields `type` and `value`, like `x::value` (will be double 1.1). Of course if you directly `typedef` the `struct_typedef::type`, you're back to square one, as you are losing the `strong` type. So basically your type should be `strong_typedef` and not `strong_typedef::type`.
One alternative that does not involve typedef and is not strongly enforced by the compiler but makes it very hard for the programmer to make mistakes it to encode the unit in question as a struct member.

For my arduino project I have types like

```
template <typename T>
struct millisecond {
    T millisecond;
    static constexpr const struct millisecond<T> zero = { 0 };
};

template <typename T>
struct microsecond {
    T microsecond;
    static constexpr const struct microsecond<T> zero = { 0 };
};

```

and use like

```
auto time_diff = millisecond<unsigned long>::zero;
time_diff.millisecond = nowMilliseconds() - s_lastPollTime.millisecond;

```

So with this strategy the compiler does not stop you from mixing units, but if you do then the error will always [scream at you](https://www.joelonsoftware.com/2005/05/11/making-wrong-code-look-wrong/):

```
total_expenses.euros = expence1.euros + expence2.dollars;

```