4 examples of 'python create array of size n' in Python

Every line of 'python create array of size n' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
53def __init__(self, size):
54 assert size > 0, "Array size must be > 0"
55 self._size = size
56 PyArrayType = ctypes.py_object * size
57 self._elements = PyArrayType()
58 self.clear(None)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

179def make_n(size, *args):
180 if sizemin <= size < sizemax:
181 subcls = classes[size - sizemin]
182 else:
183 subcls = cls_arbitrary
184 result = objectmodel.instantiate(subcls)
185 if subcls is cls_arbitrary:
186 assert isinstance(result, subcls)
187 setattr(result, attrname, [None] * size)
188 cls.__init__(result, *args)
189 return result
41def gen_array(size):
42 return ' '.join([str(i) for i in range(size * 8)])
12def create_array():
13 """Creates a simple 3D numpy array with unique values at each
14 location in the matrix.
15
16 """
17 rows, cols, depth = 2, 3, 4
18 arr = numpy.zeros((rows, cols, depth), 'i')
19 count = 0
20 for i in range(rows):
21 for j in range(cols):
22 for k in range(depth):
23 arr[i,j,k] = count
24 count += 1
25 return arr

Related snippets