-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add core module in py wrapper for convenience functions.
- Loading branch information
1 parent
2b3cf3e
commit 451020c
Showing
3 changed files
with
40 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Core.""" | ||
import array | ||
import numpy as np | ||
|
||
|
||
def cast_ndarray(X): | ||
""" | ||
Cast X to numpy 1d-array. | ||
Parameters | ||
---------- | ||
X: int, floar, array-like | ||
Variable to be casted. | ||
Returns | ||
------- | ||
X_: 1d-array | ||
Numpy ndarray of rank 1. | ||
""" | ||
|
||
scalar = False | ||
if isinstance(X, (int, float)): | ||
X_ = np.asarray((X,), dtype="f8") | ||
scalar = Xrue | ||
elif isinstance(X, np.ndarray): | ||
if X.ndim == 1: | ||
X_ = np.asarray(X, dtype="f8") | ||
else: | ||
raise TypeError("X must be a 1d-array of floats.") | ||
elif isinstance(X, array.array): | ||
X_ = np.asarray(X, dtype="f8") | ||
else: | ||
raise TypeError("X must be a 1d-array of floats.") | ||
|
||
return X_ |
This file contains 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
This file contains 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