Questions tagged [arrays]
An array is an ordered linear 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 that is specific to a programming language, tag the question with the programming language being used.
arrays
78,251
questions with no upvoted or accepted answers
14
votes
1
answer
14k
views
GraphQL loop through array and get all results
I'm new to GraphQL. I'm using API's from Amazon and Itunes to get the title (and other information) of a book. I'm returning an object like this:
var data = [];
data.title = results[0].title;
data....
13
votes
1
answer
8k
views
How to create an empty array of struct in hive?
I have a view in Hive 1.1.0, based on a condition, it should return an empty array or an array of struct<name: string, jobslots: int>
Here is my code:
select
case when <condition>
...
13
votes
3
answers
2k
views
Make sure photos are saved with the same orientation they were taken?
For some reason, my camera app saves all photos rotated 90 degrees (pictures only look right when taken with camera on landscape mode) I believe onPictureTaken should rotate photos automatically but I ...
13
votes
0
answers
1k
views
Google Native Client, sending binary data from NACL to the frontend
How do I send binary data, e.g. mp3/mp4 data back to the frontend ?
I know there are two ways of doing it: utilizing the sandbox filesystem provided by NACL and get the url at the frontend; passing ...
11
votes
2
answers
606
views
C++ array vs C# ptr speed confusion
I am rewriting a high performance C++ application to C#. The C# app is noticeably slower than the C++ original. Profiling tells me that the C# app spends most time in accessing array elements. Hence I ...
10
votes
0
answers
990
views
Numpy replace values and return new array
Is there a function in numpy similar to np.put that returns a new array instead of modifying an array in place? Something like this:
def put_copy(arr, ind, v, mode="raise"):
arr_copy = arr.copy()
...
10
votes
3
answers
3k
views
Define a C++ char array without terminator
Answers to Why this program compiles fine in C & not in C++? explain that unlike the C language, the C++ language does not tolerate an initializer string for a char array that is not long enough ...
10
votes
2
answers
251
views
std::sort invocation causes subscript out of range compile-time error
The below code fails to compile with error: "array subscript 16 is outside array bounds of …".
I don't understand why, w is guaranteed to be <= arr1.size().
https://godbolt.org/z/...
9
votes
0
answers
2k
views
Storing arrays of string persistently in SwiftUI using AppStorage
I'm trying to store an array of string in user defaults using the AppStorage property wrapper like this:
@AppStorage("History") var history: [String] = ["End of history"]
however ...
9
votes
1
answer
1k
views
Python loop taking more time at each iteration
I made a for loop which strangely increases in duration at each iteration although the amount of variables manipulated remains constant. The code is below with:
X [N*F]: a numpy array with N samples ...
9
votes
2
answers
11k
views
How can I save an empty array into mongodb using js
Basically I got my app up an running but I'm stuck with a problem: if I pass an object that contains an empty array to be saved, the array is not saved into the db. I'm not sure this is a problem in ...
8
votes
0
answers
178
views
Can you initialize a "cv char[]" with a string literal?
The current wording in [dcl.init.string] p1 states:
An array of ordinary character type, [...] may be initialized by an ordinary string literal, [...], or by an appropriately-typed string-literal ...
8
votes
0
answers
1k
views
Compiler, library, or user error? Eigen::Array, GCC 12.1, "array subscript [...] is partly outside array bounds"
After updating to GCC 12.1, I got a array subscript ‘__m256d_u[0]’ is partly outside array bounds error (or rather warning with -Werror) in my project, so I tried isolating the problem.
Here's an MWE, ...
8
votes
1
answer
700
views
numpy with mypy: indexing NDArray returns Any type
Is it possible to index numpy arrays are receive at least the same type?
Running the following code through mypy reveals the following types:
import numpy as np
from numpy.typing import NDArray
a = ...
8
votes
0
answers
302
views
Is std::launder required when performing arithmetic as well?
One of the preconditions on std::launder requires that object is within its lifetime. I assume that it is a necessary condition for being able to dereference the element. Does it mean, that if I ...