Python/List: Difference between revisions
< Python
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 6: | Line 6: | ||
for idx, item in enumerate(items): | for idx, item in enumerate(items): | ||
print(idx, val) | print(idx, val) | ||
</source> | |||
|- | |||
| NumPy || | |||
<source lang="python"> | |||
import numpy as np | |||
a = np.int32([1, 2, 3, 4]) | |||
b = np.int64([1, 2, 3, 4]) | |||
c = np.float32([1.0, 2.0, 3.0, 4.0]) | |||
d = np.float64([1.0, 2.0, 3.0, 4.0]) | |||
e = np.empty((256, 256, 4), dtype=np.uint8) | |||
a.tolist() | |||
</source> | |||
|- | |||
| map() || | |||
<source lang="python"> | |||
numbers_iter = map(int, ['1', '2', '3', '4', '5']) | |||
numbers_list = list(map(int, ['1', '2', '3', '4', '5'])) | |||
csv_line = ','.join(list(map(lambda s: '"%s"' % s, ['1', '2', '3', '4', '5']))) | |||
</source> | |||
|} | |} | ||
Latest revision as of 08:20, 17 May 2019
| TODO | Code |
|---|---|
| List with indices. |
for idx, item in enumerate(items):
print(idx, val)
|
| NumPy |
import numpy as np
a = np.int32([1, 2, 3, 4])
b = np.int64([1, 2, 3, 4])
c = np.float32([1.0, 2.0, 3.0, 4.0])
d = np.float64([1.0, 2.0, 3.0, 4.0])
e = np.empty((256, 256, 4), dtype=np.uint8)
a.tolist()
|
| map() |
numbers_iter = map(int, ['1', '2', '3', '4', '5'])
numbers_list = list(map(int, ['1', '2', '3', '4', '5']))
csv_line = ','.join(list(map(lambda s: '"%s"' % s, ['1', '2', '3', '4', '5'])))
|