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: 
You may want to take a look at the Numpy documentation. This is a good place to start:

<http://docs.scipy.org/doc/numpy/reference/routines.html>

And specifically related to your question:

<http://docs.scipy.org/doc/numpy/reference/routines.math.html>
Apart from performing vectorized operation using numpy standard vectorized functions, you can also make your custom vectorized function using [numpy.vectorize](http://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html). Here is one example:

```
    >>> def myfunc(a, b):
    ...     "Return a-b if a>b, otherwise return a+b"
    ...     if a > b:
    ...         return a - b
    ...     else:
    ...         return a + b
    >>>
    >>> vfunc = np.vectorize(myfunc)
    >>> vfunc([1, 2, 3, 4], 2)
    array([3, 4, 1, 2])

```

As mentioned in documentation, unlike numpy's standard vectorized functions, this won't improve the performance