You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Array.Sorting.Test.cs 987 B

4 years ago
12345678910111213141516171819202122232425262728293031323334
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Tensorflow;
  7. using Tensorflow.NumPy;
  8. using static Tensorflow.Binding;
  9. namespace TensorFlowNET.UnitTest.NumPy
  10. {
  11. /// <summary>
  12. /// https://numpy.org/doc/stable/user/basics.indexing.html
  13. /// </summary>
  14. [TestClass]
  15. public class ArraySortingTest : EagerModeTestBase
  16. {
  17. /// <summary>
  18. /// https://numpy.org/doc/stable/reference/generated/numpy.argsort.html
  19. /// </summary>
  20. [TestMethod]
  21. public void argsort()
  22. {
  23. var x = np.array(new[] { 3, 1, 2 });
  24. var ind = np.argsort(x);
  25. Assert.AreEqual(ind, new[] { 1, 2, 0 });
  26. var y = np.array(new[,] { { 0, 3 }, { 2, 2 } });
  27. ind = np.argsort(y, axis: 0);
  28. Assert.AreEqual(ind[0], new[] { 0, 1 });
  29. Assert.AreEqual(ind[1], new[] { 1, 0 });
  30. }
  31. }
  32. }