Questions tagged [arrays]

105126 questions
-3

votes
1

answer
43

Views

Problems with sorting an Array in Java

I´m a bloody beginner trying to write a lil programm to check if 2 words are anagrams. So far all the whitespaces within the words get deleted but apparently there's an error with my Arrays.sort() but I can´t see it. Why and where´s the error in my Arrays.sort() line and how could I solve it? Edi...
grlpwr
3

votes
3

answer
88

Views

What exactly does this log10(int) method in Java?

I'm checking a Java code from an online test and I try to understand what exactly is this log10() method. This is an image with the code from the test: I added the code in my Eclipse and I get some errors: public class Demo { public static String numbers(int from, int to) { int maxDigits = ceil(log...
gaby
0

votes
1

answer
19

Views

VBA Worksheet Loops

I'm currently working with a workbook containing 34 different tabs. I'm trying to extract Monthly Data from each of the tabs and Transpose it into daily figures for each specific city. I have put all the dates within the year 2019 as columns in order to present it as daily figures. (See example in...
David Gorgan
0

votes
2

answer
13

Views

CompactMap to filter objects that have nil properties

How do I filter out possible nil values in properties with a compactMap so I don't have to forecast a nil property to return the object. Currently I have let objects: [Object] = anotherObject.array.compactMap ({ return Object(property: $0.property!) }) What I would like is some guard staetment or op...
user1898829
0

votes
0

answer
4

Views

Whilst integrating an array of data, an axis error occured. What is the cause and solution of this error?

I have an array of data labelled y_1, for which I want to compute a definite integral of its square value, however an axis error occurs. I'm using scipy.trapz to integrate the array. I tried to define the axis as zero, however an axis error stating that the 'axis 0 is out of bounds for array of dim...
Nev045
1

votes
1

answer
5.6k

Views

Cannot index into a null array

I am using a template that sets the cell color based on a condition if a server backup was successful or not. I have the below code which is continuously throwing the error: Cannot index into a null array: Cannot index into a null array. At C:\Users\admin\Desktop\new.html.ps1:65 char:17 + ......
Vulgarito
1

votes
3

answer
1.5k

Views

Add/Replace object from array of objects JavaScript

I want to Add/Replace the object from array of objects by testing some properties against array object Replace object if name and id matches Add object to the array if name and id does not match from array objects I am using below code, its working fine but I am not sure is it a good solution. let...
Dipak Telangre
1

votes
1

answer
186

Views

TreeMap to Array. Does the array keep the order?

For every time, if I put the same values to the treeMap, the order of data in treeMap will be the same, right? No matter VM etc? I want to find out, if I convert treeMap to array on following way, I get sorted array, for every time in the same order for fixed treeMap. Map treeMap = new TreeMap(); tr...
Hadean
1

votes
3

answer
106

Views

Why does np.argwhere's result shape not match it's input?

Suppose I pass a 1D array: >>> np.arange(0,20) array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) >>> np.arange(0,20).shape (20,) into argwhere: >>> np.argwhere(np.arange(0,20)>> np.argwhere(np.arange(0,20)
user48956
1

votes
1

answer
523

Views

Kotlin - use Array<Double> or DoubleArray

What is the main difference in these two: val array: Array = arrayOf() vs val array: DoubleArray = doubleArrayOf() I know that one is using primitive data type double and the second its object based countrepart Double. Is there any penalty or disadvatnage in using plain DoubleArray? Why I want to...
Martin Perry
1

votes
3

answer
1.1k

Views

Navigating multidimensional arrays with nested for-loops in Kotlin

Quite often I am navigating a two-dimensional image matrix of pixels or a three-dimensional volumetric data set. Typically the underlying data structure is a one-dimensional array of some primitive type like Double or Int. The multi-dimensional nature is navigated through by nested for-loops as il...
J.E.Tkaczyk
1

votes
1

answer
1.6k

Views

angular 5, how do I return an array from a promise?

I am creating an array, after it is created that array is resolved as a Object. However as I need to sort tempArray based on a particular value after the resolve I need it as an array, not an Object. Also because after the sort I am displaying it using: *ngFor. Or is it better to somehow sort the...
oudekaas
1

votes
1

answer
79

Views

Contiguous allocated arrays in JavaScript/TypeScript with strings

I have a system that looks like this: interface Data { x: number; y: number; n: string; } const array = Array(100); I've read that in Chrome the V8 engine will allocate objects as C arrays if the array only contains the same type, but is it possible to actually check if my ´array´ object will act...
Frans Bstrom
1

votes
1

answer
233

Views

The filename, directory name, or volume label syntax is incorrect - when trying to readfile in go lang

I want to read contents of text file. When I am passing the file name as string like this: stream, err = ioutil.ReadFile('sample.txt') its working. Its even working if do in this way: filename := 'sample.txt' stream, err = ioutil.ReadFile(filename) But when I get the value of filename from string a...
Varun Gupta
1

votes
1

answer
1.8k

Views

Parse JSON Array in Scala

I have this jsArray (json Array) and I am using import play.api.libs.json._ library. [{”device”:”Samsung S8”,”android”:true}, {”device”:”iPhone 8”,”android”:false}, {”device”:”MacBook Air Pro”,”android”:false}, {”device”:”Dell XPS”,”android”:false}] I...
1

votes
1

answer
182

Views

Adding an array to a numpy array

I'd like to have a numpy array that looks something like this: X = np.array([[10, 20], [20, 25], [30, 16], [40, 18], [50, 90], [60, 87]]) I currently have dictionary values that I retrieve from firestore: doc_ref = db.collection('CPU Logs') query_ref = doc_ref.where(u'testData', u'==', True).order_b...
cosmo
1

votes
1

answer
34

Views

Optimize an existing for-loop over three arrays

I have three lists/arrays: one is a list of boolean values, the other two are arrays with certain values. My goal is to loop through the boolean list and if the value is true take the j-th value of the first array and safe it in the solution array, and if the value is false take the j-th value of th...
zeniapy
1

votes
2

answer
378

Views

Laravel - convert array into eloquent collection

I need to use data from an API. I create a function: public function getItems() { $client = new \GuzzleHttp\Client(); $res = $client->get('https://app.example.com/api/getItems'); $vouchers = json_decode($res->getBody(), true); dd($vouchers); return view('api', compact('vouchers')); } and dd($voucher...
Aleks Per
4

votes
4

answer
99

Views

How to find minimal non zero INT in an array in swift 5.0?

I have some array, and I need to find minimal non zero integer in each row. Is there a way of doing it with min(by:)? for example var row = [0,0,0,0,0,0,0,0,1,3,5,6,9] so I need to get 1 by doing row.min() I always get 0. I was told that I can do it with min{by:} but I don't fully understand the syn...
Oleksii
2

votes
3

answer
69

Views

Sum daily values for every month in matlab

I have got a matrix with values in. The first column of the matrix is the date in the following form, 19260701 pr YYYYMMDD. The other columns of the matrix are series. 19260702 0.026 0.000 NaN 1.175 19260706 0.009 0.000 NaN 1.842 19260707 1.388 0.001 NaN 9.061 19260708 1.14...
user30609
0

votes
0

answer
16

Views

Looping through array of objects to update another array of objects updates all objects

I currently have two arrays of objects that look like this: array1 [ { _id: { salesmanId: '5c50b6971c9d440000a4a865', week: 0 }, salesmanId: '5c50b6971c9d440000a4a865', week: 0, created: '2019-01-01T21:31:51.993Z', name: 'Craig Howell', value: 0.5 }, { _id: { salesmanId: '5c50b6971c9d440000a4a865',...
Craig Howell
0

votes
1

answer
13

Views

how to replace null values from database with empty string in chain for functions

I'm using lodash and have this code right now data: _(responseData.data) .pick(['title', 'layout', 'slug', 'author', 'seo', 'css', 'js']) .mapKeys((value, key) => _.camelCase(key)) .value() Some of the values can be returned as null from the database. I would like to replace null values with an emp...
niko craft
-1

votes
1

answer
12

Views

Treating an array of single digit numbers like a single number and adding 1 to it - Without Join(),concat() or making it a string

I have an array like so [1,9,9,9,9,9]. I want to increment this array by one and return [2,0,0,0,0,0]. Here's the catch - you can't join() or concat(). You cannot change the array in any way other than adding to it. However, you can reverse it but I'm not sure how much that would help Also, here a...
CharGar
0

votes
2

answer
33

Views

Understanding what happens within function loop

I would like to know why the inner for loop executes. My understanding is that since j = 1 and i = 0, j
uh h0 y
0

votes
2

answer
23

Views

(Java) I can't figure out how to populate an array with a counter controlled loop which is required

I have to: Create an array that models a deck of cards. For example, “1_of_diamonds” represents the ace of diamonds, “2_of_diamonds” represents the 2 of diamonds, up to “13_of_diamonds”, which represents the King of diamonds. The suits clubs, hearts and spades are represented in a simila...
Benji
0

votes
2

answer
7

Views

How do I get a different UIImage Array every time I click a button?

So basically I have a button and I need my UIImage to change randomly to one of three images in my array every time I click the button. Right now what happens when I click the button, is it just picks a random image and then when I click it again the image stays the same. Here's what I have written...
Hurtful Cow
0

votes
2

answer
13

Views

Iterate through a groupby array of json

I have an array of JSON object as follows var array = [{'id':'1','value': '13'},{'id':'2','value': '23'},{'id':'1','value': '33'},{'id':'3','value': '13'}] Then I grouped the json array according to the id as follows var groupArray = {'1':[{'id':'1','value': '13'},{'id':'1','value': '33'}], '2': [{'...
tharindu
1

votes
1

answer
51

Views

assert in foreach causes too few argument lists for macro invocation

I'm using scala test to check if Array contains Arrays of given size: result.map(_.length == 2).foreach(assert) This causes compilation error: Error:(34, 39) too few argument lists for macro invocation result.map(_.length == 2).foreach(assert) although intellij does not indicate compilation error. H...
Andronicus
1

votes
1

answer
24

Views

How to query an array for different combinations of ANDs and ORs in MongoDB Aggregation?

I am trying to search for list of students who have completed courses using different combinations of Logical ANDs and ORs. For example I want to get student who completed ('Course 1' and 'Course 2') or 'Course 3' Here is my data structure for each student : { '_id' : ObjectId('5c68841cb6b18f31975c...
Badis Merabet
1

votes
1

answer
49

Views

Different addresses of a pointer and an array in a union

I want to get the address of the first element of an array. This array is in an union with a pointer. Code: #include #include #include union l_array_0_uint8_t { uint8_t *pnt; uint8_t array[8]; }; int main() { union l_array_0_uint8_t u; uint8_t* aa = &(u.array[0]); uint8_t* pa = u.pnt; printf('arr...
peter tomson
1

votes
3

answer
70

Views

How to pass a dynamic 2d array of strings as a parameter in C++

I am trying to implement a binary tree as a 2d array. I want the user to enter the required height of the tree and the program should give an appropriate size array. Then, I want to print the array, which is why I need to pass it as a parameter. However, I get the following error: arrayTree/main.cpp...
uhexos
1

votes
2

answer
26

Views

Having Trouble Populating an Array of Structures from Reading a File

I'm trying to populate an array with values from this file: 9383 8.86 2777 69.15 7793 83.35 5386 4.92 6649 14.21 2362 0.27 8690 0.59 7763 39.26 540 34.26 9172 57.36 5211 53.68 2567 64.29 5782 15.30 2862 51.23 4067 31.35 3929 98.02 4...
yiwll
1

votes
2

answer
288

Views

Numpy: Combine list of arrays by another array (np.choose alternative)

I have a list of numpy arrays, each of the same shape. Let's say: a = [np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), np.array([[11, 12, 13], [14, 15, 16], [17, 18, 19]]), np.array([[99, 98, 97], [96, 95, 94], [93, 92, 91]])] And I have another array of the same shape that gives the list indices I wan...
Max16hr
1

votes
3

answer
56

Views

Create a Input and Label for each object in an array

I have populated an array with a list of ingredients. I need to make a dynamically create a checkbox & label combo for each object (just the 'Name' Object) within the array here is the code that I am trying to create for each object in the array Doughnuts I need to replicate that code fragment for e...
Humza Yusuf
1

votes
2

answer
35

Views

Copying Type String Array to Range in Excel - Invalid Qualifier

I want to transfer the contents from part of the a 'Type' array to an excel range (see example below), but get 'Invalid Qualifier' error. Any help would be appreciated? Public Type typDetails firstName As String lastName As String End Type Dim userDetails(100) As typDetails Public Sub test() userDet...
Alex
1

votes
4

answer
37

Views

Check if a list of byte arrays contains a new byte array

I have a list of byte arrays and need to check if this list doesn't contain a new given byte array. If not, than I need to perform some action. Right now, I'm trying to do it like this: List listOFByteArrays = getListOfByteArrays(); byte[] newByteArray = getNewByteArray(); if (!listOfByteArrays.cont...
Coffemanz
1

votes
1

answer
37

Views

Pasting VBA Array into Excel Range

I know this question has been asked multiple times, but I am kinda stuck adopting the suggested solutions to my problem. I have an array(0 to 4), that gets filled multiple times in a loop and should be pasted each time into a new line in excel. Expected Output: A | B | C |...
Maeaex1
1

votes
2

answer
31

Views

PHP transposing an associative array and padding missing cells?

I have the following data which has gender and age category specific results of a race. The data is returned as an associative array. In most categories I have three results, but in certain categories there might only be 1 or 2 results. M50,1,9197,V50,M M50,2,8253,V50,M M50,3,18282,V50,M W50,1,19961...
emeraldjava
1

votes
1

answer
52

Views

std::array<T, N> with complex type and N=256/large [duplicate]

This question already has an answer here: How to initialize std::array elegantly if T is not default constructible? 3 answers I am looking for a way to fill an std::array with T being a non-default-constructible struct/class and N indeed being known at compile time, but so large, that you don't wan...
christianparpart
1

votes
4

answer
56

Views

How to get a multidimensional array's name?

I'm trying to get the name of an array once I have found a specific value. Specifically I'm looking to get the highest and lowest values within my array for a certain key, once I have those values I then need to get the name of the array holding those values. My array looks like this - Array ( [123...
Zakariiah

View additional questions