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: 
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)

```
If you're not trying to do anything complicated, the original code could be implemented this way as well, without requiring the use of numpy, if I'm not mistaken.

```
>>> import math
>>> x = range(1, 101)
>>> y = [ 20 * math.log10(z) for z in x ]

```