Knowing where you are: custom array indices in Julia
julialang.org
julialang.org
Numpy arrays on the other hand are awkward to use in custom algorithms because once the memory is reserved, you can't grow the array at either end.
edit: if anyone knows a solution to this, please let me know...
The amortized complexity is θ(1), but individual insertions might take O(n) time.
It means that it is not hard to have the same in numpy, with the same performance, the only difference is that the growing have to be done manually and that the push_back function has to be called as something like
x, x_len = push_back(x, x_len, 10)
with push_back being defined like def push_back(x, x_len, value):
if len(x) == x_len:
x = np.concatenate((x, np.empty(max(len(x), 1)))
x[x_len] = value
return x, x_len + 1
so that the x variable is supposed to be updated after each insertion.Btw. you can grow them using hstack and vstack although I am not sure how efficient that is.
>> last_elem = arr[-1]
>> rev_arr = arr[::-1] # Reverse array
I don’t understand what you’re proposing. You want a spreadsheet where the row and column headings have arbitrary starting point?
First thing that comes to mind is time-series data - like a sliding window based on some concept of "now" where indices can be offset by the current date/time. (e.g. timeSeries[0] == now, timeSeries[-1] == one second ago, timeSeries[1] == one second in the future, etc.)
I actually find these linear-algebra based languages even more mind-bending than functional based languages.
You're just using Object/map behavior, and if you're doing that with negative indices on an Array Object you're misusing it.
I've rewritten someobject#[] plenty of times to have cleaner code.
Julia can inline through all the `getindex!` functions so you get the same performance as with a hand-coded C or Fortran array.