Anaconda / Python: Change Anaconda Prompt User Path

In Windows, if you have the shortcut in your taskbar, right-click the “Anaconda Prompt” icon, you’ll see: Anaconda Prompt Unpin from taskbar (if pinned) Close window Right-click on “Anaconda Prompt” again. Click “Properties” Add the path you want your anaconda prompt to open up into in the “Start In:” section. Note – you can also … Read more

How to initialize weights in PyTorch?

Single layer To initialize the weights of a single layer, use a function from torch.nn.init. For instance: Alternatively, you can modify the parameters by writing to conv1.weight.data (which is a torch.Tensor). Example: The same applies for biases: nn.Sequential or custom nn.Module Pass an initialization function to torch.nn.Module.apply. It will initialize the weights in the entire … Read more

Find the nth occurrence of substring in a string

Mark’s iterative approach would be the usual way, I think. Here’s an alternative with string-splitting, which can often be useful for finding-related processes: And here’s a quick (and somewhat dirty, in that you have to choose some chaff that can’t match the needle) one-liner:

When should I be using classes in Python?

Classes are the pillar of Object Oriented Programming. OOP is highly concerned with code organization, reusability, and encapsulation. First, a disclaimer: OOP is partially in contrast to Functional Programming, which is a different paradigm used a lot in Python. Not everyone who programs in Python (or surely most languages) uses OOP. You can do a … Read more