Question: I want to implement the following Matlab code in Python:

```
x=1:100;
y=20*log10(x);

```

I tried using Numpy to do this:

```
y = numpy.zeros(x.shape)
for i in range(len(x)):
    y[i] = 20*math.log10(x[i])

```

But this uses a for loop; is there anyway to do a vectorized operation like in Matlab? I know for some simple math such as division and multiplication, it's possible. But what about other more sophisticated operations like logarithm here?

Answer: 
```
y = numpy.log10(numpy.arange(1, 101)) * 20

```

---

```
In [30]: numpy.arange(1, 10)
Out[30]: array([1, 2, 3, 4, 5, 6, 7, 8, 9])

In [31]: numpy.log10(numpy.arange(1, 10))
Out[31]:
array([ 0.        ,  0.30103   ,  0.47712125,  0.60205999,  0.69897   ,
        0.77815125,  0.84509804,  0.90308999,  0.95424251])

In [32]: numpy.log10(numpy.arange(1, 10)) * 20
Out[32]:
array([  0.        ,   6.02059991,   9.54242509,  12.04119983,
        13.97940009,  15.56302501,  16.9019608 ,  18.06179974,  19.08485019])

```
Numpy has a lot of built-in array operators like [log10](http://docs.scipy.org/doc/numpy/reference/generated/numpy.log10.html). If it's not listed in numpy's documentation and you can't generate it from combining built-in methods, then there's no easy way to do it efficiently. You can implement a C-level function to work on numpy arrays and compile that, but this is a lot more work than one or two lines of Python code.

For your case you almost have the right output already:

```
y = 20*numpy.log10(x)

```