42 if not isinstance(n, int):
43 raise TypeError(
"Value should be integer.")
48 if not (isinstance(f, float)
or isinstance(f, int)):
49 raise TypeError(
"Value should be float.")
54 if isinstance(b, bool):
56 if isinstance(b, (int, float)):
62 raise ValueError(
"Will not cast non 0/1 int or float to boolean.")
63 raise TypeError(
"Will only cast int and float to booleans.")
68 if isinstance(data, (int, float, complex)):
73 if scalar_expand
or size == 1:
74 return np.full(size, data[0], dtype=dtype)
76 raise TypeError(
"This non-singleton array cannot " + \
77 "be initialized with a scalar.")
80 raise TypeError(
"Input argument has wrong number of elements.")
81 if isinstance(data, np.ndarray)
and len(data.shape) > 1:
82 raise TypeError(
"Multidimensional ndarray input is not allowed")
84 list)
and not all([isinstance(x, (float, int, complex))
86 raise TypeError(
"Input list may only contain numerical values.")
89 return np.array(data, dtype=dtype)
93 if not isinstance(data, np.ndarray):
94 raise TypeError(
"Input argument must be a np.ndarray")
97 if len(data.shape) != len(shape):
99 for (i, j)
in zip(data.shape, shape):
100 if j != -1
and i != j:
104 "Input has wrong dimensions, expect multi dimensional arrays")
106 return np.array(data, dtype=dtype)