7 examples of 'initialize array in python' in Python

Every line of 'initialize array in python' 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
13def __init__(self, arr):
14 assert arr is not None
15 self.shape = arr.shape
16 self.array = arr
17 self.size = self.array.size
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)
97def __init__(self, elemtype, *ignored):
98 '''Note: elemcount is ignored when using in the Python scope.
99 '''
100 self.elemtype = elemtype
490def __init__(self, array, on_shape_change='raise'):
491 """
492 array is a numpy array of data.
493 on_shape_change is one of ('raise', 'pass', 'recompile'), and
494 determines the behaviour when the data is set to a new value with a
495 different shape
496 """
497 super(DataHolder, self).__init__()
498 dtype = normalize_dtype(array)
499 self._array = np.asarray(array, dtype=dtype)
500 assert on_shape_change in ['raise', 'pass', 'recompile']
501 self.on_shape_change = on_shape_change
301def __init__(self, db, ARRAY, varlength=1):
302 self.db = db
303 self.ARRAY = ARRAY
304 self.LLTYPE = ARRAY
305 self.varlength = varlength
306 self.dependencies = {}
307 self.itemtypename = db.gettype(ARRAY.OF, who_asks=self)
17def __init__(self,
18 *array: Union[np.ndarray, pd.DataFrame, pd.Series,
19 torch.Tensor],
20 dtypes: Union[None, Sequence[torch.dtype]] = None):
21 if dtypes is None:
22 dtypes = [torch.get_default_dtype()] * len(array)
23 if len(dtypes) != len(array):
24 raise ValueError('length of dtypes not equal to length of array')
25
26 array = [
27 self._convert(data, dtype) for data, dtype in zip(array, dtypes)
28 ]
29 super().__init__(*array)
40def init_array(C, A, B, alpha, beta):
41 n = N.get()
42 m = M.get()
43
44 alpha[0] = datatype(1.5)
45 beta[0] = datatype(1.2)
46
47 for i in range(m):
48 for j in range(n):
49 C[i, j] = datatype((i + j) % 100) / m
50 B[i, j] = datatype((n + i - j) % 100) / m
51 for i in range(m):
52 for j in range(i + 1):
53 A[i, j] = datatype((i + j) % 100) / m
54 for j in range(i + 1, m):
55 A[i, j] = -999
56 # regions of arrays that should not be used
57
58 print('aval', beta[0] * C[0, 0] + alpha[0] * B[0, 0] * A[0, 0])

Related snippets