Question: I was recently working with Python and wanted to use another way of finding square roots. For example I wanted to find square root of n with Newton-Raphson approximation. I need to overload the overload the `**` (only when you raise a number to 0.5),o perator as well as `math.sqrt()`, because I have several older projects that could be sped up by doing so and replacing all `math.sqrt()` and `**(0.5)` with another function isn't ideal.

Could this be done in Python?

Is it possible to overload either `**` or `math.sqrt`?

Any helpful links are also much appreciated.

```
def Square_root(n):
    r = n/2
    while(abs(r-(n/r)) > t):
        r = 0.5 * (r + (n/r))
    return r

print(2**(0.5)) ## changes to print(Square_root(2))
print(math.sqrt(2)) ## that also becomes print(Square_root(2))

```

Answer: 
I think the error comes because in the `transform.Compose` you are doing first `.ToTensor()` and, instead, you should do `.Scale()`. `Pytorch` has transformations on **tensors** and on **PIL Images**, that are *not* interchangeable.
Reading the docs it says 

> 
> class torchvision.transforms.Scale(size, interpolation=2) [...]
>  Rescale the input PIL.Image to the given size.
> 
> 
> 

While you are changing that image to a Pytorch tensor before scaling thus making it crash.

It should be changed to:

```
transform = transforms.Compose(
                   [transforms.Scale((32,32)),
                    transforms.ToTensor(),
                    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

```

You will get this error when applying `PIL Image` transformations on tensors.
For your question, I think `transforms.ToTensor()` before `transform.Scale((32, 32))` is not right.

In the document of `Scale::__call__(self, img)` already show

> 
> Args: img(PIL.Image): Image to be scaled.
> 
> 
> 

So the input for `Scale` is `PIL.Image` not `Tensor`.

```
transform = transforms.Compose(
[transforms.ToTensor(),
 transforms.Scale((32,32)),
 transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

```

So you could try the following one:

```
transform = transforms.Compose([transforms.Scale((32,32)),
                                transforms.ToTensor(),
                                transforms.Normalize((0.5, 0.5, 0.5), 
                                                     (0.5, 0.5, 0.5))])

```

You can the script to load your custom dataset at [this gist](https://gist.github.com/xpzouying/8078000043a0713056ba14490a90807b). Click [here](https://raw.githubusercontent.com/xpzouying/animals-classification/master/images/gist1.png) to the result of the script.

I post the full classification in custom images, you could check it at **github.com/xpzouying/animals-classification**