Last active
July 13, 2018 15:01
-
-
Save caiofcm/01f914a1787edd3b73fc03a902a1b374 to your computer and use it in GitHub Desktop.
python simple auxiliary functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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