Skip to content

Commit 77d3b55

Browse files
committed
Added np.newaxis (not supported yet)
1 parent f7ba7f2 commit 77d3b55

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/NumSharp.Core/APIs/np.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public static partial class np
1010
{
1111
public static BackendType BackendEngine { get; set; }
1212

13+
/// <summary>
14+
/// A convenient alias for None, useful for indexing arrays.
15+
/// </summary>
16+
/// <remarks>https://docs.scipy.org/doc/numpy-1.17.0/reference/arrays.indexing.html<br></br><br></br>https://stackoverflow.com/questions/42190783/what-does-three-dots-in-python-mean-when-indexing-what-looks-like-a-number</remarks>
17+
public static readonly Slice newaxis = new Slice(null, null, 1) {IsNewAxis = true};
18+
1319
// https://docs.scipy.org/doc/numpy-1.16.0/user/basics.types.html
1420
public static readonly Type bool_ = typeof(bool);
1521
public static readonly Type bool8 = bool_;

src/NumSharp.Core/Backends/Unmanaged/UnmanagedStorage.Slicing.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ public UnmanagedStorage GetView(params Slice[] slices)
2020
throw new ArgumentNullException(nameof(slices));
2121

2222
foreach (var slice in slices)
23+
{
2324
if (slice.IsEllipsis)
2425
throw new NotSupportedException("Ellipsis slicing '...' is not supported by NumSharp.");
25-
26+
if (slice.IsNewAxis)
27+
throw new NotSupportedException("np.newaxis slicing '...' is not supported by NumSharp. Consider calling np.expand_dims after performing slicing");
28+
}
2629
//handle memory slice if possible
2730
if (!_shape.IsSliced)
2831
{

0 commit comments

Comments
 (0)