Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What languages have similar or equivalent array slicing notation to Numpy & why is it not more common? [closed]

Specifically when indexing n>3 dimensional arrays / vectors, why do more languages not adopt the:

arr = np.zeros((3, 10, 5, 100)) 
arrSlice = arr[:, 0:5, :, :99]

>   arrSlice.shape
>   (3, 5, 5, 99)

style notation for slicing arrays (If I'm not just missing something)...?

Do any other languages have equivalent notation to Numpy, either syntactically or functionally?

Is this something where it's syntactic sugar over Numpy performing more linear looping in C that creates a dichotomy between python / C / cupy that's not available or sensible in other languages? (For e.g., I'm assuming numpy's batch operation notation ends up as sequential looping at a lower level at some point)

Are tensors just not generally very useful / practical data structures outside of machine learning? If so is that more because of most languages not being easily able to execute array operations in parallel using GPUs? Or is it more that people tend not to want to think in multidimensional matrices? Something else?

Are there alternatives in other languages that are equivalent or superior that I'm just not familiar with? It seems like most tend to focus along the first dimension for e.g.:

var x = [[0, 1], [2, 5], [3, 4]]

let methodSlice = x.slice(0, 2)
let spreadSlice = &x[0..2];

> [[0, 1], [2, 5]] 

I miss this aspect of python more than anything else in it and it seems like tensors are comparatively less accessible elsewhere.

Thanks ahead of time for any insight you might have, it is a bunch of questions but I couldn't find any equivalent question that had yet been asked.

like image 980
Charles Avatar asked Mar 02 '20 14:03

Charles


People also ask

What is the equivalent of NumPy in C++?

xtensor is a C++ library that is BSD licensed. It offers A C++ API very similar to that of NumPy.

What language does NumPy use?

NumPy (pronounced /ˈnʌmpaɪ/ (NUM-py) or sometimes /ˈnʌmpi/ (NUM-pee)) is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.

What is array slicing in Python?

Slicing arrays Slicing in python means taking elements from one given index to another given index. We pass slice instead of index like this: [start:end] . We can also define the step, like this: [start:end:step] .

Can NumPy arrays be sliced?

NumPy arrays can be defined using Python sequences such as lists and tuples. Lists and tuples are defined using [...] and (...) , respectively.


1 Answers

R's slicing notation is similar: https://bookdown.org/ndphillips/YaRrr/slicing-dataframes.html

like image 185
Zach Cleary Avatar answered Oct 23 '22 10:10

Zach Cleary