| @@ -37,6 +37,6 @@ namespace Tensorflow.NumPy | |||||
| } | } | ||||
| public NDArray normal(float loc = 0.0f, float scale = 1.0f, Shape size = null) | public NDArray normal(float loc = 0.0f, float scale = 1.0f, Shape size = null) | ||||
| => throw new NotImplementedException(""); | |||||
| => new NDArray(random_ops.random_normal(size ?? Shape.Scalar, mean: loc, stddev: scale)); | |||||
| } | } | ||||
| } | } | ||||
| @@ -47,6 +47,8 @@ namespace Tensorflow.NumPy | |||||
| return GetData(mask.ToArray<int>()); | return GetData(mask.ToArray<int>()); | ||||
| else if (mask.dtype == TF_DataType.TF_INT64) | else if (mask.dtype == TF_DataType.TF_INT64) | ||||
| return GetData(mask.ToArray<long>().Select(x => Convert.ToInt32(x)).ToArray()); | return GetData(mask.ToArray<long>().Select(x => Convert.ToInt32(x)).ToArray()); | ||||
| else if (mask.dtype == TF_DataType.TF_FLOAT) | |||||
| return GetData(mask.ToArray<float>().Select(x => Convert.ToInt32(x)).ToArray()); | |||||
| throw new NotImplementedException(""); | throw new NotImplementedException(""); | ||||
| } | } | ||||
| @@ -18,6 +18,9 @@ namespace Tensorflow.NumPy | |||||
| [AutoNumPy] | [AutoNumPy] | ||||
| public static NDArray log(NDArray x) => new NDArray(tf.log(x)); | public static NDArray log(NDArray x) => new NDArray(tf.log(x)); | ||||
| [AutoNumPy] | |||||
| public static NDArray mean(NDArray x) => new NDArray(math_ops.reduce_mean(x)); | |||||
| [AutoNumPy] | [AutoNumPy] | ||||
| public static NDArray multiply(NDArray x1, NDArray x2) => new NDArray(tf.multiply(x1, x2)); | public static NDArray multiply(NDArray x1, NDArray x2) => new NDArray(tf.multiply(x1, x2)); | ||||
| @@ -14,6 +14,12 @@ namespace TensorFlowNET.UnitTest | |||||
| tf.Context.ensure_initialized(); | tf.Context.ensure_initialized(); | ||||
| } | } | ||||
| public bool Equal(float f1, float f2) | |||||
| { | |||||
| var tolerance = .000001f; | |||||
| return Math.Abs(f1 - f2) <= tolerance; | |||||
| } | |||||
| public bool Equal(float[] f1, float[] f2) | public bool Equal(float[] f1, float[] f2) | ||||
| { | { | ||||
| bool ret = false; | bool ret = false; | ||||
| @@ -23,5 +23,15 @@ namespace TensorFlowNET.UnitTest.NumPy | |||||
| Assert.AreEqual(x.shape, 10); | Assert.AreEqual(x.shape, 10); | ||||
| Assert.AreNotEqual(x.ToArray<int>(), y.ToArray<int>()); | Assert.AreNotEqual(x.ToArray<int>(), y.ToArray<int>()); | ||||
| } | } | ||||
| /// <summary> | |||||
| /// https://numpy.org/doc/stable/reference/random/generated/numpy.random.normal.html | |||||
| /// </summary> | |||||
| [TestMethod] | |||||
| public void normal() | |||||
| { | |||||
| var x = np.random.normal(0, 0.1f, 1000); | |||||
| Equal(np.mean(x), 0f); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||