79 questions
5
votes
2
answers
91
views
How to pass cell indexing as an input argument to a function, such that cell inside the function can use the indexing directly?
I am wondering if we can pass cell indexing as an input argument to a function, such that a cell inside the function can parse it.
For example, given a cell like x = num2cell(reshape(1:24, [2,3,4])), ...
0
votes
0
answers
84
views
Can't access data added inside a strategy
I am trying to backtest a rebalancing strategy using performance of SPX. The (simplified) idea is: if price is above 200day moving average, then buy top 10 tickers on a pre-loaded list. If price is ...
0
votes
1
answer
69
views
Writing to multidimensional arrays with variable dimension
I've initialized a list of arrays of different dimensions in Python and want to write to the entries of the arrays. If I want to write to the entry list[i, m1, m1, ..., m1, m2, m2, ..., m2] where m1 ...
1
vote
1
answer
68
views
How to correctly code to output the summation of all numbers in a given range of index (1 to N) for each query from a given array in C?
Problem:
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
Given 2 numbers N and Q, an array A of N number and Q number of pairs L, ...
0
votes
1
answer
102
views
How can I get the index of an array in DOS Assembly x86 (16-bit)?
I would like to know how to deal with the index of an array. My objective is to get and change the value at a specific index.
My array looks like this:
Dots_pos dw firstLine, firstLine+ 8, ...
-1
votes
1
answer
113
views
How to assert that a string can be used as an array index w/o converting/asserting it to/as a number?
I have a string value, which I intend to use as an index of an array. I'm sure of this value and want to assert that it's a valid 'index value', w/o converting it to a number at runtime or asserting ...
0
votes
1
answer
702
views
Does array.map() starts iterating from the 1st element throughout the array?
Is n automatically set to represent array indexes starting from 0? What confuses me is that I usually set up for loops to define i as an index indicator. But here how does n do it without being set ...
1
vote
1
answer
79
views
Accessing the first index of an anonymous function [duplicate]
If I have an anonymous function in MATLAB, say
f = @(t) [t, t+5];
and I wanted to create a new anonymous function g that accesses the first index of f, so that, in this example,
g = @(t) t;
how can ...
1
vote
1
answer
99
views
Python Array variable assignment
I am newbie to python so having difficulty understand this code behavior for scenarios listed below.
I can understand the first 3 where the output is a=[1], b=[0] but in the last case why is the value ...
1
vote
1
answer
99
views
My names are not being erased from the list. Assembly language x86
scrienume label let's me read from the keyboard 5 char names.The lista label displays each on one line along with their index(eg:if i write "daria" and "adria", the output is "...
1
vote
1
answer
59
views
I want to filter the columns with condition '>0' and den find minimum value along filtered columns and sort them and get index of column using numpy
I am looking for this solution using Numpy, So anyone wish to do this operation/steps with minimal code it would help me a lot.
Step 1. This is the given array arr_a=
[[0, 1.2, -0.3, 8, 3, -4],
[1.3,...
0
votes
0
answers
33
views
C# Array with specific LowerBound [duplicate]
This question for learning C#, and not a real problem.
I was reading in C# that you can create an Array with custom LowerBound so it won't start from Zero.
I thought this might be useful where I can ...
1
vote
2
answers
617
views
NumPy 3D Array: Get items from a list of 2D co-ordinates
I have a numpy array that looks like follows.
img = [
[
[135. 100. 72.],
[124. 102. 63.],
[161. 67. 59.],
[102. 92. 165.],
[127. 215. 155.]
],
[
[254. 255. 255.],
...
1
vote
1
answer
719
views
The difference between double brackets vs single square brackets in python
I am trying to Sort the array by the second row. For n1, I use two square brackets [][] whereas for n2 I use a single square bracket [,]. I am trying to understand why do I get different results?
...
0
votes
4
answers
171
views
last index of array give wrong output in c
I created a program that search the specific number in array and give it position.
here's the code.
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[10], srch, i;
clrscr();...
0
votes
1
answer
239
views
How to reassign/replace a value of an array by index if its in a global state
I have a global state that is an array [1,0, null,1,0....] I want to access the array by index let's say index 5 I want just to replace that value with 1 I have the array and I have the index but I ...
1
vote
1
answer
108
views
Get Matrix 2D from Matrix 3D with a given choice of the third dimension corresponding to the first dimension
I have:
A matrix 3D: A = (m, n, k).
An array of choices for the third dimension corresponding to each index of the first dimension. idn = (m, 1) (wherein the value of any idn is a random integer in [...
2
votes
1
answer
134
views
2D array 3x9 matrix get the index of the next two elements of the current index and check if it is equal to 0
I am a total newbie to programming and i have been following some tutorials on array related to housie ticket generator.The point where I am stuck is that, I have to check each rows and each rows of ...
-1
votes
1
answer
366
views
JQuery for each function get array index
I have an array as follows:
result = [];
result.push({label: 'test label 1', value: 'test value 1'});
result.push({label: 'test label 2', value: 'test value 2'});
$.each(result, ...
2
votes
2
answers
151
views
Subdimensional array from multidimensional array in Julia
With NumPy I can access a subdimensional array from a multidimensional array without knowing the dimension of the original array:
import numpy as np
a = np.zeros((2, 3, 4)) # A 2-by-3-by-4 array of ...
0
votes
1
answer
676
views
fill remaining indexes in array with null values
I need to adjust for blank days in my calendar app. There should be 35 blocks to make up the calendar, but I need to fill the array with 30 items inside of that. Is there a method that allows that?
so ...
0
votes
0
answers
55
views
np.array([0, 0, 0]) [ [1, 2, 2] ] += [4, 5, 6] does not accumulate
All arrays in the following are NumPy arrays.
I have an array of numbers, say a = [4, 5, 6].
I want to add them to an accumulation array, say s = [0, 0, 0]
but I want to control which number goes to ...
4
votes
1
answer
1k
views
OrderedDictionary key name at specified index
Given an ordered dictionary, I would like to get the key at index 0. I can of course do a loop, get the key of the first iteration and immediately break out of the loop. But I wonder if there is a way ...
1
vote
2
answers
192
views
C++ use class with conversion operator as index into array
#include <cinttypes>
#include <type_traits>
template<typename Id, typename Value>
class sparse_set {
static_assert(std::is_integral_v<Id>, ""); (1)
...
-1
votes
1
answer
329
views
iOS/Swift: why contains doesn't work to detect a substring in the .firstIndex function?
I am using the function .firstIndex to locate a specific substring in an array of arrays.
But when I put the entire string, it works, but if I put only a substring of that string, this doesn't work.
...
2
votes
2
answers
403
views
IOS/Swift: How to indicate the first position of the $0 in the .firstIndex ? 'Cannot convert value of type 'Any' to expected argument type 'String''
I would like to search a value in an array of arrays, like in this example but I don't know how to indicate it "the position of the first element in $0" ?
var programArray: [Any] = []
let ...
1
vote
1
answer
2k
views
Angular Index of nested loop inside Template
I have a nested loop in a table, but i want to only show a limited amount of rows in the DOM and load more when a button is clicked.
The Loop looks something like this:
<ng-container *ngFor="...
0
votes
1
answer
160
views
Indices in Numpy and MATLAB
I have a piece of code in Matlab that I want to convert into Python/numpy.
I have a matrix ind which has the dimensions (32768, 24). I have another matrix X which has the dimensions (98304, 6). When I ...
-1
votes
1
answer
101
views
Is it possible to overload [] operator to do different thing in C++
I want to overload "[]" witch is used to access array
But I also want to separate read/write to do different thing
For example :
class myclass{
private:
int val;
public:
myclass(){...
0
votes
2
answers
2k
views
Product of array in a new array except the current index value
Given an array of integers, create a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i.
For example, if our input ...
1
vote
1
answer
214
views
Is there a way to extract a solid box slice of an arbitrary multidimensional Python array given two sets of corner index coordinates?
Suppose I have a = np.arange(16).reshape(4,4), which is
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]])
And want to slice a as I could with a[0:3,...
3
votes
2
answers
105
views
How can numpy array indexing techniques can give different outputs for same input code?
#Code
import numpy as np
np.random.seed(124)
x_2d = np.random.randint(1,50,(3,4,5))
print("I am getting wrong output => {}".format(x_2d[0][:][1]))
print("This is what I want =&...
2
votes
3
answers
573
views
2D array random index Lotto game
I'm trying to do a Lotto game where I have to generate a random card and in the first column numbers go from 1-9, second 10-19 all the way to 90. Another rule of the card is that it can only have 5 ...
0
votes
3
answers
911
views
Indexing multidimensional array
Is it possible in Java to index an Array somehow like arr1[arr2] if arr1 is an int[][] and arr2 an int[2].
I would like a better way to achieve the same as arr1[arr2[0]][arr2[1]] which looks really ...
-1
votes
3
answers
203
views
Easier way to represent indicies in a 2D array
I'm new to programming and I've created a simple tic-tac-toe game. It took an input of the row and column of a 2d array. However, I want to make it simpler and use a value of 1-9 instead to represent ...
0
votes
2
answers
49
views
Incremental and Decremental of javascript array
I'm trying to create simple image modal using angular material. next() supposed to be view next image from the array and prev() view previous image.
Problem
next and prev function not working as ...
0
votes
0
answers
195
views
Can't access array value when my index is a variable
I have a problem accessing a value stored in my 2D array...
When I write the index as a number, it works but when my index is a variable (which contains a number) it does not work...
Here is my code:
#...
-2
votes
3
answers
488
views
How to make a +5 (or any +number) jump in array values inside a for loop? [closed]
So i have a column of data which consists of numbers where i have to find 5 instances of the same number.
So ,for example, 8,8,8,8,8,8,8,8,8,9,9,9,5,6,4,7,,6,2,3, etc. In this 8 has occurred 9 times. ...
6
votes
1
answer
2k
views
What is meant by ^1 as array index (e.g. arr[^1]) in C#? [duplicate]
int []arr = new int[4];
arr[^1]; // returns the last element
I'm trying to figure out the syntax above. It's returning the last element, but why?
1
vote
1
answer
2k
views
PowerShell printing only first letter of a string
I have a PowerShell script that connects to a localhost API that returns a dictionary of "sessions" and whether they are active
[System.Reflection.Assembly]::LoadWithPartialName("System....
0
votes
3
answers
2k
views
How do you get the index number of an array rather than the element?
I have written a basic program to find the largest number in an array and print it:
#include <stdio.h>
int main(void)
{
int numbers[] = {3, 5, 12, 1, 4};
int largest;
largest = ...
0
votes
1
answer
450
views
Assign values of vertical vector from matrix to variables in MATLAB r2019b
What I want to be able to do is to take the elements of a vertical vector from a matrix and assign them to variables. I have provided a simple example below to show what I want to happen.
for k = 1 : ...
-2
votes
2
answers
119
views
JS Function that checks a dynamic number of index positions and returns array element if it satisfies the condition [closed]
I've been looking for a way to return elements in an array based on a dynamic number. This dynamic number will be the number of required index positions for each array element, if each element can ...
2
votes
1
answer
9k
views
Bigquery: Find the index at which a specified element is first found within an array
I'm working with Bigquery and I have a dataset with arrays where I'd like to extract the index at which a specified element is first found. I do not find a function in Bigquery to achieve what I want. ...
0
votes
1
answer
197
views
Making a back button using previous state of the array index
I'm making a back button for a decision tree. The tree is made out of an array and its index. Right now, yes or no will take them to a different part of the array index as a response. I'm trying to ...
1
vote
2
answers
1k
views
VHDL 2008: Index in external names containing generated instances
For a testbench, I'm trying to use external names to read signals within a DUT. It is not desired to export these signals outside of the DUT, so I concluded that using external names was the best ...
0
votes
1
answer
47
views
Sub-array using $p$ commas
Say I have an array Y of size (n x m_1 x m_2 x m_3). If I want the first sub-array of size (m_1 x m_2 x m_3) I can choose it using commas as
Y(1,,,)
Similarly, if Y is of size (n x m_1 x m_2 x m_3 x ...
2
votes
1
answer
4k
views
Initializing arrays in VHDL: How exactly does it work?
Consider the following VHDL code:
constant c : std_logic_vector(7 downto 0) := (7 downto 6 => '1', others => '0');
Here, the indices 7 and 6 are important: they indicate which elements should ...
0
votes
0
answers
84
views
Why does Kotlin in Android Studio freeze when trying to access non existent array element?
I've come across interesting behavior of Kotlin in Android Studio. When I try to log an element of an array dynamically where the index supplied is -1 and the array is empty, the program freezes in ...
1
vote
1
answer
218
views
Handling NaN / Inf in a numpy dnarray
Working on a 4D numpy array (array of arrays). Each nested array is of shape (1, 100, 4)
trainset.shape
(159984, 1, 100, 4)
But then within the nested arrays, are found some nan values which I would ...