Every line of 'how to take 2d array input in python using numpy' 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.

By copying the Snyk Code Snippets you agree to

this disclaimer

73 def as2d( ar ): 74 """ 75 If the input array is 2D return it, if it is 1D, append a dimension, 76 making it a column vector. 77 """ 78 if ar.ndim == 2: 79 return ar 80 else: # Assume 1! 81 aux = np.array( ar, copy = False ) 82 aux.shape = (ar.shape[0], 1) 83 return aux

Important

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

69 def convert_image_np_2d(inp): 70 inp = denorm(inp) 71 inp = inp.numpy() 72 # mean = np.array([x/255.0 for x in [125.3,123.0,113.9]]) 73 # std = np.array([x/255.0 for x in [63.0,62.1,66.7]]) 74 # inp = std* 75 return inp

162 def _convert_to_numpy(data): 163 """Returns tuple data with all elements converted to numpy ndarrays""" 164 if data is None: 165 return None 166 elif isinstance(data, tuple): 167 return tuple([_convert_to_numpy(d) for d in data]) 168 elif isinstance(data, np.ndarray): 169 return data 170 elif isinstance(data, (pd.DataFrame, pd.Series)): 171 return data.to_numpy() 172 else: 173 raise Exception("Unsupported type %s" % str(type(data)))

321 def _atleast_2d_with_dtype(value, dtype=None): 322 323 if dtype is not None: 324 value = np.array(value, dtype=dtype) 325 326 arr = np.atleast_2d(value) 327 328 return arr

21 def data_tranform2d(data): 22 """ 23 :param data: 24 :return data2d: 25 26 Returns the data array reshaped into 2-dimensions 27 """ 28 shape, dimensions = data_shape(data) 29 30 if dimensions == 1: 31 raise TypeError('Data must have dimensions between 2 and 4') 32 33 elif dimensions == 2: 34 return data 35 36 elif dimensions == 3: 37 return np.reshape(data, (shape[0]*shape[1], shape[2])) 38 39 elif dimensions == 4: 40 return np.reshape(data, (shape[0]*shape[1]*shape[2], shape[3])) 41 42 else: 43 raise TypeError('Data must have dimensions between 2 and 4')

37 def array(a): 38 return numpy.array(a)

246 def atleast_3d(ary): 247 """ 248 numpy.atleast_3d adds axes on either side of a 1d array's axis, but I want the new axes to come afterward. 249 :param ary: 250 :type ary: 251 :return: 252 :rtype: 253 """ 254 ary = numpy.asanyarray(ary) 255 if len(ary.shape) == 0: 256 result = ary.reshape(1, 1, 1) 257 elif len(ary.shape) == 1: 258 result = ary[:, None, None] 259 elif len(ary.shape) == 2: 260 result = ary[:,:, None] 261 else: 262 result = ary 263 264 return result

42 def array2d(X, dtype=None, order=None, copy=False): 43 """Returns at least 2-d array with data from X""" 44 if sp.issparse(X): 45 raise TypeError('A sparse matrix was passed, but dense data ' 46 'is required. Use X.toarray() to convert to dense.') 47 X_2d = np.asarray(np.atleast_2d(X), dtype=dtype, order=order) 48 _assert_all_finite(X_2d) 49 if X is X_2d and copy: 50 X_2d = safe_copy(X_2d) 51 return X_2d