Category "arrays"

Finding the middle element(s) of an array in Java

Given an array of integers, I need to return a new array containing the middle element(s) from the original array. Specifically, the result will have one elemen

Transpose csv file data [duplicate]

I need help to assign keys to an array in PHP. My code is: //First I make an array of a csv file $file="C:\path-to-csv\file.csv"; $csv= file

How to group by the elements of an array in Swift

Let's say that I have this code: class Stat { var statEvents : [StatEvents] = [] } struct StatEvents { var name: String var date: String var hours

Get keys from associative array [duplicate]

I have this array: Array ( [7] => 12 [5] => 11 [4] => 11 [2] => 9 [8] => 7 [1] => 6 [3] => 6 [6] => 5 [23] => 3 [3

Get keys from associative array [duplicate]

I have this array: Array ( [7] => 12 [5] => 11 [4] => 11 [2] => 9 [8] => 7 [1] => 6 [3] => 6 [6] => 5 [23] => 3 [3

How to divide an array by an other array element wise in numpy?

I have two arrays, and I want all the elements of one to be divided by the second. For example, In [24]: a = np.array([1,2,3])

Write a program to print the sum of all the elements of an array of size N where N can be any integer between 1 and 100 [closed]

Write a program to print the sum of all the elements of an array of size N where N can be any integer between 1 and 100. (1 \le N \le 100) Ins

How can I access an array/object?

I have the following array and when I do print_r(array_values($get_user));, I get: Array ( [0] => 10499478683521864 [1] => 07/22/1983

Updating a NumPy array with another

Seemingly simple question: I have an array with two columns, the first represents an ID and the second a count. I'd like to update it with another, similar arr

Reverse array in Javascript without mutating original array

Array.prototype.reverse reverses the contents of an array in place (with mutation)... Is there a similarly simple strategy for reversing an array without alter

How to count occurrences of an element in a Swift array?

I've seen a few examples of this but all of those seem to rely on knowing which element you want to count the occurrences of. My array is generated dynamically

How to detect array start index by current shells (zsh/bash)?

We all know arrays in Bash are indexed from zero, and in zsh are indexed from one. How can the script know it should use 0 or 1 if I can't ensure the running en

How to detect array start index by current shells (zsh/bash)?

We all know arrays in Bash are indexed from zero, and in zsh are indexed from one. How can the script know it should use 0 or 1 if I can't ensure the running en

Inserting a key-value pair in a specified position of a JS Map object (akin to Array's .splice()) [duplicate]

Is there a way to performance-efficiently insert a key-value pair in a specific place of a Map object? The problem I'm trying to solve is sto

Best Way to Update/Edit an Array Element in SwiftUI

I have an array of identifiable Training elements. Each Training element only has two properties, name and isRequired. What is the most straight-forward (Swif

For each loop using 2D array

This is the snippet of Java code: int[][] uu = new int[1][1]; uu[0][0] = 5; for(int[] u: uu){ System.out.println(u[0]); } It prints 5. But why does the d

Find the Longest Subarray

Given an array of integers, what is the length of the longest subarray containing no more than two distinct values such that the distinct values differ by no mo

What is PHP's equivalent of JavaScript's "array.every()"?

I'm currently trying to port some JavaScript over to PHP. However, I can't seem to find PHP's equivalent to the JavaScript array.every() function. I found PHP's

How to go to next line after every row in a 2D array?

So I need to come up with something like this: It's a layout of seats on an airplane. 1 A B C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D

Array to string conversion

$replacements = array( '{order_id}' => $order_id, '{site_url}' => $settings["site_url"], '{email}' => $user_email, '{last_name}' =&g