Common Python Mistakes & Fixes

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/25

flashcard set

Earn XP

Description and Tags

A quick reference set covering common mistakes in Python coding practice, including tensor definitions, bias usage, and handling multiple conditions.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

26 Terms

1
New cards

What is the correct way to define a tensor with torch.tensor?

Use a tuple with a single argument, enclosed in brackets ( ).

2
New cards

What common mistake happens when defining a tensor?

Forgetting that torch.tensor expects a tuple with just one argument.

3
New cards

How should you check for bias in a class method?

Use if self.bias: — always include self for class functions.

4
New cards

What is the role of self in Python class methods?

It ensures the method has access to the instance’s attributes and functions.

5
New cards

What should you be careful of when using multiple and and or statements?

Verify all possible cases and ensure logic is grouped correctly.

6
New cards

What happens if one of the conditions in a complex and/or chain isn’t satisfied?

The result may not behave as expected — test each case explicitly.

7
New cards

What is the shape of the weight matrix

(out_features, in_features)

8
New cards

How do you define self.weights

self.weights = nn.Parameters(torch.empty(out_featuree, in_features))

9
New cards

Bias parameter

self.register_parameter(“bias”, None)

10
New cards

Initializjing weights

nn.init.xavier_uniform(self.weight)

11
New cards

Matrix Multiplication

torch.nn.functional.linear(x, self.weight, self.bias)

12
New cards

What are Modules and Parameters

Modules is a nueral network

Parameter is weight for one layer.

13
New cards

Relu

torch.clamp(x, min=0)

14
New cards

Tanx

torch.ones_like(x)/ (torch.oneslike(x) + torch.exp(-x))

15
New cards

Leaky Relu

torch.where(x>=0, x, x*negative_slope)

Gradient is negative slope

16
New cards

What is channels in computer vision

self.channels = channels in the dataset that represent different features or color depths of the images, typically corresponding to RGB in color images.

17
New cards

How do you increase number of channels

Run multiple number of kernels in parallel.

18
New cards

Paramerters for kernel

stride, padding, kernel_size

19
New cards

What does x.shape for for compute rvision

batch_size, in_channels, input_h, input_w

20
New cards

Padding

x = F.pad(x,(padding[1],padding[1], padding[0]. padding[0]])

21
New cards

Symbol for integer multiplication

//

22
New cards

What does a*b do for tensors

It deoes elementwise multiplicaiton and not mtrix multiplixation.

23
New cards

How do you get sum of all entires in a matrix

torch.sum(a)

24
New cards

Max Pooling`

Runs a max kernel over the input. The max value is taken from each region covered by the kernel, reducing the dimensions of the input.

25
New cards
26
New cards