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: 
There are several ways to solve this, but since I was looking for a fix to Bjarne's code in the presentation slides, I'm accepting this answer which @robson3.14 left in comments to the question:

```
#include <iostream>

template<int M, int K, int S> struct Unit { // a unit in the MKS system
    enum { m=M, kg=K, s=S };
};

template<typename Unit> // a magnitude with a unit
struct Value {
    double val; // the magnitude
    // construct a Value from a double
    constexpr explicit Value(double d) : val(d) {} 
};

using Meter = Unit<1,0,0>; // unit: meter
using Second = Unit<0,0,1>; // unit: sec
using Speed = Value<Unit<1,0,-1>>; // meters/second type

// a f-p literal suffixed by ‘_s’
constexpr Value<Second> operator "" _s(long double d)
{
    return Value<Second> (d);
}
// a f-p literal suffixed by ‘_m’
constexpr Value<Meter> operator "" _m(long double d)
{
    return Value<Meter> (d);
}
// an integral literal suffixed by ‘_m’
constexpr Value<Meter> operator "" _m(unsigned long long d)
{
    return Value<Meter> (d);
}

template<int m1, int k1, int s1, int m2, int k2, int s2>
Value<Unit<m1 - m2, k1 - k2, s1 - s2>> operator / (Value<Unit<m1, k1, s1>> a, Value<Unit<m2, k2, s2>> b)
{
    return Value<Unit<m1 - m2, k1 - k2, s1 - s2>>(a.val / b.val);
}

int main()
{
    Speed sp1 = 100_m / 9.8_s;
    std::cout << sp1.val;
}

```
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;

```