Questions tagged [arrays]
An array is an ordered data structure consisting of a collection of elements (values, variables or references), each identified by one or more indexes. When asking about specific variants of arrays, use these related tags instead: [vector], [arraylist], [matrix]. When using this tag, in a question which is specific to a programming language, tag the question with the programming language being used.
316,525
questions
0
votes
0answers
4 views
How to generate synthetic data for predicting the type of ball bearing
I want to generate synthetic data for predicting the grade of the ball bearing which is a continuous number in the range of 2 to 10. This is assigned randomly or if somebody can propose a logical way ...
0
votes
1answer
38 views
using an array as a condition in an if loop
I'm brand new to python and pretty new to coding in general, so please bear with me.
I'm trying to execute the for loop:
for numi,i in enumerate(v1):
for numj,j in enumerate(v1):
angle=(np....
1
vote
2answers
17 views
How to modify the value of numpy array based on another array?
I have a numpy array. I want to modify one array index by the chosen elements of another array. For example:
import numpy as np
t1 = np.ones((10,3))
t2 = np.arange(10)
t1[np.where(t2>5)][:,2] = 10
...
0
votes
1answer
17 views
is it possible to create an array of type declarations in c++?
I was wondering if there was a way to create an array that contains type declarations to more easily and more flexibly declare a larger number of variables of different types.
For instance, what I'm ...
1
vote
3answers
26 views
I cannot display an array of object by using console.log in JavaScript
I created the array of object showing each movie title and rating. However I try to use console.log("You have watched " + movieObject.movieDB[0]);, the property, movieDB does not show, instead it ...
1
vote
2answers
41 views
JavaScript minus zero changes results
I was playing around with Arrays in jsfiddle and noticed that when I do this:
let a = [0,1,2,3,4];
for (let i in a) {
console.log(a.indexOf(i));
}
it logs:
But when I do:
let a = [0,1,2,3,4];
...
-2
votes
0answers
15 views
How to achieve this array manipulation in php [duplicate]
I have an array like below
Array
(
[0] => Array
(
[id] => 12
[type_name] => Coffee
[nlp_engine] => dialogflow
)
[1] => ...
0
votes
0answers
13 views
Direct indexing into 2d Numpy array using another Numpy array as the (y,x) coordinates
I searched around if this is possible... It seems pretty straightforward so maybe I missed something.
I have a 2D numpy array:
#####################################
################################...
-1
votes
0answers
17 views
Javascript: get a range of an array of strings [closed]
So, I have an array, that could look like this:
["1","2","3","4","5"]
It might as well look like this:
["4","7"]
I want to get all items that match
["2","3","4"]
so in the first case, I would get
["...
0
votes
0answers
13 views
How I can get object from another function
I'm trying to do a Shopping cart with HTML and JS. So I'm using (https://www.smashingmagazine.com/2019/08/shopping-cart-html5-web-storage/).
In my function save(), I have,
`function save(id, title, ...
0
votes
1answer
37 views
JS - Object property doesn't take the assigned value but get only the last value of array
I have an array of objects, each object has a list of id, like this:
objects: [
{
ids: [1,2],
name: 'alpha'
},
{
ids: [2,3],
name: 'bravo'
}
]
I want ...
1
vote
1answer
28 views
Javascript -Trim Array of URL's to Root Domain
I am developing a chrome extension that can copy the urls of all tabs in a browser. The problem is i can only trim one url in all the array. Is there a way i can output all the root domain in the ...
-1
votes
0answers
25 views
min pair of consecutive numbers of array
I need the minimun adjacent pair of a given array with dynamic programming.
Why isnt working?
def prepare(array):
list = []
for i in range(len(array)-1):
lista.append(sum(array[i:i+2]...
0
votes
3answers
23 views
2D struct array: swap row and col?
I want to swap the entire column and row of a 2D struct array.
With this code I can swap rows:
#define N 9
typedef struct {
char number;
bool editable;
} FIELD;
int main(){
FIELD **f = (...
-1
votes
4answers
31 views
Get elements of an array based on indexes from another table
I have two arrays.
One with my data:
var tab1 = ["one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","...
0
votes
1answer
24 views
Issues implementing a search function “TypeError: data.filter is not a function”
EDIT: heres the console.log(data) the data is displaying fine, it's just not filtering the data properly..]
!https://imgur.com/a/SsEDAKj!
EDIT 2: this.state.items is an array.
I'm trying to ...
0
votes
1answer
23 views
Why my menu is not working as it should? Scanner not working as well
package hangman;
import java.util.ArrayList;
import java.util.Scanner;
public class Hangman {
public static void main(String[] args) {
int maxGuess = 5; // chances or life
String ...
-1
votes
1answer
23 views
add together numbers from an array who have 3 factors only
array = [3,6,7,9,21,100] so only 6 and 21 should be added together
below is what I have tried
def getFactors(n):
# Create an empty list for factors
factors=[];
# Loop over all factors
for i in ...
2
votes
2answers
36 views
JavaScript - Sort array by two integer properties [duplicate]
I have the following array of objects:
const items = [
{ name: "Different Item", amount: 100, matches: 2 },
{ name: "Different Item", amount: 100, matches: 2 },
{ name: "An Item", amount: ...
0
votes
1answer
27 views
Mapping between ids and indices using numpy arrays
I'm working on a graphical application that uses shapes such as quads, trias, lines etc. to represent geometry.
The input data is based on ID's.
A list of points is provided, each with an ID and ...
0
votes
0answers
12 views
Need help to display string array inside of a 2d grid [closed]
After I input my rows and columns and enter in each word, that is shorter than the length of columns.(as many times as there are rows) my method at the bottom of the page is supposed to overwrite my ...
-1
votes
1answer
23 views
min sum of consecutive values with Divide and Conquer
Given an array of random integers
N = [1,...,n]
I need to find min sum of two consecutive values using divide and conquer.
What is not working here but my IQ?
def minSum(array):
if len(array) &...
0
votes
1answer
12 views
extract a specific field from array in Google Sheets
I am executing a function in Google Sheets which is resulting into an array output like below
Col1 Col2
A B
10 20
What I want is to fetch only 20 and I don't want other rows and ...
0
votes
3answers
39 views
Sort one array by another with duplicate values?
You can sort two arrays using one as the leading.
arr1inds = lead_arr1.argsort()
sorted_arr1 = lead_arr1[arr1inds]
sorted_arr2 = arr2[arr1inds]
The question is how would you do this if both arrays ...
0
votes
8answers
44 views
Javascript ES5: How to Group By a key and create Sub objects from a flat array of key-value objects without using Lodash or Underscore
I have an array of Objects with 4 keys:
[
{
"team": "USA",
"team_profile_id": "10",
"player": "Captain America",
"player_id": "10X1"
},
{
"team": "USA",
"...
-1
votes
1answer
32 views
C++ array with fixed size? [duplicate]
for example, I created a static array with fixed size 4 and I use indexing operator [] to assign the fifth element(which is not suppose to exist I thought) to 100. It did not give me any compiler ...
-1
votes
1answer
22 views
Referencing Array items across MVC program (JavaFX application)
This is my first question on StackOverflow and I thank anyone who can help in advance. I am trying to complete a javaFX application using the Model View Controller design pattern. My application is a ...
0
votes
0answers
23 views
Why my code gets “java.lang.NullPointerException” when I try to add Item to array? [duplicate]
when I use addItem method on empty array or full array it gives me NullPoiterException.
Is that error caused be an equals method?
it works well if the array has some items and method adds new items, ...
1
vote
2answers
30 views
Add many pandas dataframes with overlapping indexes and columns
What is the best way provided by pandas to combine many dataframes, and perform mathematical addition of the values at the overlapping rows and columns?
I have a long list of overlapping dataframes ...
-3
votes
0answers
17 views
What are some practical uses of 2D and 3D arrays in Java? [closed]
I know how to code them, but I'd like to try a few real-world examples to get a better understanding of their utility.
0
votes
1answer
37 views
Angular Frontend - Save in an Array
I'm new to Angular. So sorry if that's an obvious thing, that I'm supposed to know.
I'm getting a String[] from the backend and I want to save various strings in it, by typing them in a mat-form-...
2
votes
3answers
52 views
How do I initialize a pointer to an array of pointers?
I am trying to initialize a pointer to an array of pointers. Here's an example:
class MyClass { };
// INTENT: define a pointer to an array of pointers to MyClass objects
MyClass* (*myPointer)[];
...
4
votes
2answers
58 views
Why must the expanded array be dynamically allocated for this function to work properly C++
I have been working on a function that accepts an array and an array size as an argument. The functions task is to create a second array that is twice the size of the fist array, copying the elements ...
1
vote
4answers
63 views
Using a 2D array to store weather data. c++
So im creating a program that would store weather data inside a 2D array and i have everything set up for the most part, i think, but im stuck on actually storing it in the array. This is what i have:
...
3
votes
3answers
63 views
Can you mimic dynamic array sizes using 'new' in C++?
I know you can make a dynamically sized array using malloc, but I'm interested in doing the same thing using new, partly because malloc is considered bad practice in C++ and mostly out of curiosity.
...
0
votes
1answer
47 views
Valgrind throws invalid free() when I try to free an array of dynamically allocated pointers
I'm allocating an array of pointers that are dynamically allocated and I try to free them at the end of my program. The problem is that I always get a "invalid free()" error on valgrind, though I ...
0
votes
0answers
30 views
How to parse a small subset of Markdown into React components?
I have a very small subset of Markdown along with some custom html that I would like to parse into React components. For example, I would like to turn this following string:
hello *asdf* *how* _are_ ...
0
votes
0answers
25 views
How to multiply double arraylist values with corresponding string arraylist
Context
I have an assignment that is asking me to read a recipe from a text file and manipulate the contents like units of measurement and ingredient quantity's. I separated the parts of the recipe ...
0
votes
0answers
44 views
How to store the RGB values of a ppm file to an array in C++
The assignment is to manipulate a PPM file and to store the RGB values to an array. I am able to grab the header of the file and get P6, the width, the height, and the maximum RGB value but I cannot ...
1
vote
1answer
30 views
array of strings with string interpolation
i have an array of strings like below
const array = ["string1", "string2", "string3"];
const total = 10000;
and i have a url that has string interpolation like below
const url = `http://localhost:...
0
votes
1answer
31 views
Google Sheets COUNTIF doesn't function with boolean values [SOLVED]
I'm looking for the equivalent of the COUNTIF(A1:A100;TRUE) formula of excel,
which won't happen to function in google sheets.
Had already tried to SUM(--(A1:A100)), neither this doesn't seem to do ...
1
vote
1answer
25 views
MS Access VBA using ReDim Preserve to increase the size of an array when needed( as in within a button click event handler method or within a loop )
I'm new to Microsoft Office Professional Plus 2013 Access.
I am developing an application using:
-Microsoft Office Professional Plus 2013 Access
I my VBA Editor, I have the following Class Module:
...
0
votes
1answer
27 views
How do I access a variable, created outside of an IF/ELSE scope, update it in the IF statement, and access that update in the ELSE statement?
Sorry, I'm not sure how else to word my question and, as such, am having a hard time finding any relevant solutions.
The Project
I'm creating a script that cleans batches of raw text from an Excel ...
0
votes
1answer
53 views
Can you save multiple separate lists to localStorage?
I'm working on a project that will take user input and store it into a list in localStorage. I want to be able to have three of these to do lists on the page.
I have put the code into three separate ...
0
votes
1answer
28 views
How can i replace multiple specific strings in an array with objects using one function?
this is what the table looks like
When i press book (in Granbo row), I want the field in Granbo-row (under "vinter") to change to "utleid"(means "not availible" in norwegian). I can hardcode it for ...
-1
votes
1answer
20 views
How to fix unset json object in php
I have below json object,
{
"products": [{
"type": "HR_ECLAIM",
"name": "HR Claims",
"is_fixed_price": true,
"price": 500.5,
"currency": "MYR",
"status"...
0
votes
1answer
40 views
I have an array that should be an object [closed]
There is an object in the data object, that I wrote as an object, but if I console.log it, the browser says that it's an array. But I clearly gave it the object brackets. The tutorial that I am ...
0
votes
1answer
30 views
VBA Array function converts variable with a simple type to a value and does not store variable reference
VBA Array function converts variable with a simple type to a value and does not store variable reference. But if I pass a class variable it works as intended. Is it supposed to be like that or I'm ...
0
votes
1answer
49 views
How to insert key,value pair of object to an array?
i have an object like this:
var obj = {
0: {...},
1: {...},
2: {...},
3: {...},
4: {...}
}
And then i have an if statement with some logic to see wich values i want in each key. If ...
1
vote
4answers
34 views
JavaScript Objects - I'm having issues accessing an array of objects properties nested multiple levels & combining them together
I have an array of objects & those objects contain a property called children which are also objects & they repeat them multiple levels deep(or not).
Basically, I need to accomplish two ...