0% found this document useful (0 votes)
10 views

Python Way of Coding

summary note of python way of coding

Uploaded by

dominique.t5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Way of Coding

summary note of python way of coding

Uploaded by

dominique.t5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

How to code in python:

HOW TO CREATE EMPTY ARRAY IN ADVANCE THAT CAN STORE ELEMENT OF ANY
SIZE IN NUMPY:
img_resized = np.empty(heights.size, dtype=object)

LIBRARIES :
- import argparse: for parsing

 GPU CUDA:
GPU_index = "0"
os.environ["CUDA_VISIBLE_DEVICES"] = GPU_index

 Inside class:
◦ Inheritance:
▪ super(UNet, self).__init__()

◦ private method and variable:
▪ _loadEntry(self) : underscore for private function

◦ checkConsistency(self):
pass
◦ Empty Function
▪ def quick_load_data(self, patch_shape): raise NotImplementedError

◦ try and except

◦ type hint return and type:


▪ def projectPointsToImagePlane(self, point_cloud: np.ndarray) ->
np.ndarray :
▪ def projectPointPairsToCameraPlane(self,points_left:
list,points_right: list,cmu) -> list :
▪ def select(self, indices=None, sequence_name_list = None):
▪ def centerline_to_occupancyGrid(centerline: Centerline,
occupancy_grid: OccupancyGrid = None) -> OccupancyGrid :
▪ ...etc
▪ from typing import Tuple
def FindMinMaxLargestRegionArray(hist: np.array) ->
Tuple[int,int,int]:

 Aliasing:
AnnotationList = typing.List[float]
CmuList= typing.List[algorithm.CameraModelCMU]
def calculate_centerline_from_annotation(annotation_list: AnnotationList,
cam_list: CmuList ):

 Class Particular function:


◦ def __getitem__(self,idx):
◦ def __getstate__(self):
◦ def __setstate__(self, state):
◦ def __repr__(self):

 class Decorateur;
◦ @classmethod
◦ @staticmethod

 python keyword:
◦ enumerate
◦ zip
◦ unzip
◦ raise
▪ raise ValueError("`border_mode` not in ['valid', 'same']")

 Short conditional:
conv_op = nn.Conv2d if ndims == 2 else nn.Conv3d

 [I] * 10 ==> table of I, 10 elements

 Usage of the start:


◦ https://www.geeksforgeeks.org/python-star-or-asterisk-operator/

 initialize np.array
◦ np.array([])

FLUENT PYTHON:
CHAPTER 1
The Python Data Model

The following is a very simple example, but it demonstrates the power of implementing
just two special methods, __getitem__ and __len__ .

Card = collections.namedtuple('Card', ['rank', 'suit'])

class FrenchDeck:
ranks = [str(n) for n in range(2, 11)] + list('JQKA')
suits = 'spades diamonds clubs hearts'.split()
def __init__(self):
self._cards = [Card(rank, suit) for suit in self.s for rank in self.ranks]
def __len__(self):
return len(self._cards)
def __getitem__(self, position):
return self._cards[position]

NAMETUPLE:
beer_card = Card('7', 'diamonds')
>>> beer_card
Card(rank='7', suit='diamonds')

You might also like