Skip to content

Commit 7b0a9b7

Browse files
committed
Array, Memoryview, Threading, NumPy, Image
1 parent f55a355 commit 7b0a9b7

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

README.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ with <conn>: # Exits the block with commit()
19261926
[(1, 'Jean-Luc', 187)]
19271927
```
19281928

1929-
### SqlAlchemy
1929+
### SQLAlchemy
19301930
**Library for interacting with various DB systems via SQL, method chaining, or ORM.**
19311931
```python
19321932
# $ pip3 install sqlalchemy
@@ -2034,22 +2034,22 @@ b'\x00\x01\x00\x02\x00\x00\x00\x03'
20342034

20352035
Array
20362036
-----
2037-
**List that can only hold numbers of a predefined type. Available types and their minimum sizes in bytes are listed above. Type sizes and byte order are always determined by the system, however bytes of each element can be swapped with byteswap() method.**
2037+
**List that can only hold numbers of a predefined type. Available types and their minimum sizes in bytes are listed above. Type sizes and byte order are always determined by the system, however bytes of each element can be reversed with byteswap() method.**
20382038

20392039
```python
20402040
from array import array
20412041
```
20422042

20432043
```python
20442044
<array> = array('<typecode>', <coll_of_nums>) # Array from collection of numbers.
2045-
<array> = array('<typecode>', <bytes>) # Array from bytes object.
2045+
<array> = array('<typecode>', <bytes>) # Copies bytes to array's memory.
20462046
<array> = array('<typecode>', <array>) # Treats array as a sequence of numbers.
2047-
<array>.fromfile(<file>, n_items) # Appends items from the binary file.
2047+
<array>.fromfile(<file>, n_items) # Appends items from binary file.
20482048
```
20492049

20502050
```python
20512051
<bytes> = bytes(<array>) # Returns a copy of array's memory.
2052-
<file>.write(<array>) # Writes array's memory to the file.
2052+
<file>.write(<array>) # Writes array's memory to binary file.
20532053
```
20542054

20552055

@@ -2059,7 +2059,7 @@ Memory View
20592059

20602060
```python
20612061
<mview> = memoryview(<bytes/bytearray/array>) # Immutable if bytes, else mutable.
2062-
<obj> = <mview>[index] # Returns int, float or bytes ('c' format).
2062+
<obj> = <mview>[index] # Returns int/float (bytes if format is 'c').
20632063
<mview> = <mview>[<slice>] # Returns mview with rearranged elements.
20642064
<mview> = <mview>.cast('<typecode>') # Only works between B/b/c and other types.
20652065
<mview>.release() # Releases memory buffer of the base object.
@@ -2069,7 +2069,7 @@ Memory View
20692069
<bytes> = bytes(<mview>) # Returns a new bytes object.
20702070
<bytes> = <bytes>.join(<coll_of_mviews>) # Joins mviews using bytes as a separator.
20712071
<array> = array('<typecode>', <mview>) # Treats mview as a sequence of numbers.
2072-
<file>.write(<mview>) # Writes `bytes(<mview>)` to the file.
2072+
<file>.write(<mview>) # Writes `bytes(<mview>)` to binary file.
20732073
```
20742074

20752075
```python
@@ -2156,8 +2156,8 @@ with <lock>: # Enters the block by calling acq
21562156
<bool> = <Future>.cancel() # Cancels or returns False if running/finished.
21572157
<iter> = as_completed(<coll_of_Futures>) # `next(<iter>)` returns next completed Future.
21582158
```
2159-
* **Map() and as\_completed() also accept 'timeout'. It causes futures.TimeoutError when next() is called/blocking. Map() times from original call and as_completed() from first call to next(). As\_completed() fails if next() is called too late, even if thread finished on time.**
2160-
* **Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. Its exception() method returns exception or None.**
2159+
* **Map() and as\_completed() also accept 'timeout'. It causes futures.TimeoutError when next() is called/blocking. Map() times from original call and as_completed() from first call to next(). As\_completed() fails if next() is called too late, even if all threads have finished.**
2160+
* **Exceptions that happen inside threads are raised when map iterator's next() or Future's result() are called. Future's exception() method returns exception object or None.**
21612161
* **ProcessPoolExecutor provides true parallelism but: everything sent to/from workers must be [pickable](#pickle), queues must be sent using executor's 'initargs' and 'initializer' parameters, and executor should only be reachable via `'if __name__ == "__main__": ...'`.**
21622162

21632163

@@ -2680,7 +2680,7 @@ import numpy as np
26802680

26812681
```python
26822682
<array> = np.concatenate(<list_of_arrays>, axis=0) # Links arrays along first axis (rows).
2683-
<array> = np.row_stack/column_stack(<list_of_arrays>) # Treats 1d arrays as rows or columns.
2683+
<array> = np.vstack/column_stack(<list_of_arrays>) # Treats 1d arrays as rows or columns.
26842684
<array> = np.tile/repeat(<array>, <int/list> [, axis]) # Tiles array or repeats its elements.
26852685
```
26862686
* **Shape is a tuple of dimension sizes. A 100x50 RGB image has shape (50, 100, 3).**
@@ -2772,7 +2772,7 @@ from PIL import Image
27722772
<Image> = Image.new('<mode>', (width, height)) # Creates new image. Also `color=<int/tuple>`.
27732773
<Image> = Image.open(<path>) # Identifies format based on file's contents.
27742774
<Image> = <Image>.convert('<mode>') # Converts image to the new mode.
2775-
<Image>.save(<path>) # Selects format based on extension (png/jpg…).
2775+
<Image>.save(<path>) # Selects format based on extension (PNG/JPG…).
27762776
<Image>.show() # Opens image in the default preview app.
27772777
```
27782778

@@ -2795,10 +2795,11 @@ from PIL import Image
27952795
```
27962796

27972797
### Modes
2798-
* **`'L'` - Lightness (i.e. greyscale). Each pixel is an int between 0 and 255.**
2799-
* **`'RGB'` - Red, green, blue (i.e. true color). Each pixel is a tuple of three ints.**
2800-
* **`'RGBA'` - RGB with alpha. Low alpha (forth int) means more transparency.**
2801-
* **`'HSV'` - Hue, saturation, value color space.**
2798+
* **`'L'` - Lightness (greyscale image). Each pixel is an int between 0 and 255.**
2799+
* **`'RGB'` - Red, green, blue (true color image). Each pixel is a tuple of three ints.**
2800+
* **`'RGBA'` - RGB with alpha. Low alpha (i.e. forth int) makes pixel more transparent.**
2801+
* **`'HSV'` - Hue, saturation, value. Three ints representing color in HSV color space.**
2802+
28022803

28032804
### Examples
28042805
#### Creates a PNG image of a rainbow gradient:
@@ -2823,14 +2824,14 @@ img.show()
28232824
### Image Draw
28242825
```python
28252826
from PIL import ImageDraw
2826-
<ImageDraw> = ImageDraw.Draw(<Image>) # Object for adding 2D graphics to the image.
2827-
<ImageDraw>.point((x, y)) # Draws a point. Truncates floats into ints.
2828-
<ImageDraw>.line((x1, y1, x2, y2 [, ...])) # To get anti-aliasing use Image's resize().
2829-
<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2) # Always draws in clockwise direction.
2830-
<ImageDraw>.rectangle((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste().
2831-
<ImageDraw>.polygon((x1, y1, x2, y2, ...)) # Last point gets connected to the first.
2832-
<ImageDraw>.ellipse((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste().
2833-
<ImageDraw>.text((x, y), <str>, font=<Font>) # `<Font> = ImageFont.truetype(<path>, size)`
2827+
<Draw> = ImageDraw.Draw(<Image>) # Object for adding 2D graphics to the image.
2828+
<Draw>.point((x, y)) # Draws a point. Truncates floats into ints.
2829+
<Draw>.line((x1, y1, x2, y2 [, ...])) # To get anti-aliasing use Image's resize().
2830+
<Draw>.arc((x1, y1, x2, y2), deg1, deg2) # Always draws in clockwise direction.
2831+
<Draw>.rectangle((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste().
2832+
<Draw>.polygon((x1, y1, x2, y2, ...)) # Last point gets connected to the first.
2833+
<Draw>.ellipse((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste().
2834+
<Draw>.text((x, y), <str>, font=<Font>) # `<Font> = ImageFont.truetype(<path>, size)`
28342835
```
28352836
* **Use `'fill=<color>'` to set the primary color.**
28362837
* **Use `'width=<int>'` to set the width of lines or contours.**

0 commit comments

Comments
 (0)