Skip to content

Instantly share code, notes, and snippets.

@caiofcm
Last active July 13, 2018 15:01
Show Gist options
  • Select an option

  • Save caiofcm/01f914a1787edd3b73fc03a902a1b374 to your computer and use it in GitHub Desktop.

Select an option

Save caiofcm/01f914a1787edd3b73fc03a902a1b374 to your computer and use it in GitHub Desktop.
python simple auxiliary functions
def cat_vector(args):
noArray = False
for y in args:
if isinstance(y, np.ndarray):
if y.size != 1:
x = y
noArray = True
break
if noArray == False:
raise 'One of the args has to be a numpy array'
try:
r, c = x.shape
except (ValueError, AttributeError):
r = 0
c = 0 #Just use hstack
if r > 1 and c == 1:
return np.vstack(args)
else:
return np.hstack(args)
def import_rel(rel, module_name = None):
import sys
import os
path_string = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if not sys.path.__contains__(path_string):
sys.path.append(path_string)
if module_name is not None:
__import__(module_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment