[SYSTEMML-1431] Throw controlled error when one-dimensional numpy array is passed to SystemML
Here is an example pyspark session demonstrating this PR: >>> from mlxtend.data import mnist_data >>> import numpy as np >>> from sklearn.utils import shuffle X, y = mnist_data() from systemml import MLContext, dml ml = MLContext(sc) script = dml('print(sum(X))').input(X=X) ml.execute(script) script = dml('print(sum(X))').input(X=y) ml.execute(script) script = dml('print(sum(X))').input(X=y.reshape(-1, 1)) ml.execute(script)>>> X, y = mnist_data() >>> from systemml import MLContext, dml >>> ml = MLContext(sc) Welcome to Apache SystemML! >>> script = dml('print(sum(X))').input(X=X) >>> ml.execute(script) 1.31267102E8 MLResults >>> script = dml('print(sum(X))').input(X=y) >>> ml.execute(script) ... TypeError: Expected 2-dimensional ndarray, instead passed 1-dimensional ndarray. Hint: If you intend to pass the 1-dimensional ndarray as a column-vector, please reshape it: input_ndarray.reshape(-1, 1) >>> script = dml('print(sum(X))').input(X=y.reshape(-1, 1)) >>> ml.execute(script) 22500.0 Closes #438. Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/a1d73f80 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/a1d73f80 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/a1d73f80 Branch: refs/heads/gh-pages Commit: a1d73f805bc6a94e953c0b999269b79fcbb07a16 Parents: 7407b70 Author: Niketan Pansare <npan...@us.ibm.com> Authored: Thu Mar 23 11:41:16 2017 -0700 Committer: Niketan Pansare <npan...@us.ibm.com> Committed: Thu Mar 23 11:44:33 2017 -0700 ---------------------------------------------------------------------- beginners-guide-python.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/a1d73f80/beginners-guide-python.md ---------------------------------------------------------------------- diff --git a/beginners-guide-python.md b/beginners-guide-python.md index ffab09e..24f7151 100644 --- a/beginners-guide-python.md +++ b/beginners-guide-python.md @@ -183,7 +183,7 @@ y_train = diabetes.target[:-20] y_test = diabetes.target[-20:] # Train Linear Regression model X = sml.matrix(X_train) -y = sml.matrix(y_train) +y = sml.matrix(np.matrix(y_train).T) A = X.transpose().dot(X) b = X.transpose().dot(y) beta = sml.solve(A, b).toNumPy()