Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何在 python 中按比例调整数组的大小,例如:
原来的:
1 0 0 1
调整大小:
1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1
代码:
original = [] row1 = [1,0] row2 = [0,1] original.append(row1) original.append(row2) #how resize?
多谢。
如果你真的想用 Python 列表做到这一点:
SCALE_MULTIPLE = 2 # or any positive integer new_array = [] for orig_row in original: new_row = [] for orig_elem in orig_row: new_row.extend([orig_elem] * SCALE_MULTIPLE) new_array.extend(new_row[:] for _ in range(SCALE_MULTIPLE))