Tag: arrays

57 votes
16 answers
1.9K views
How to sum array of numbers in Ruby?

I have an array of integers. For example: array = [123,321,12389] Is there any nice way to get the sum of

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
62 votes
30 answers
1.1K views
Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missing

I had an interesting job interview experience a while back. The question started really easy: Q1: We have a b

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
57 votes
8 answers
403 views
How do I iterate through each element in an n-dimensional matrix in MATLAB?

I have a problem. I need to iterate through every element in an n-dimensional matrix in MATLAB. The problem is

avatar
Chaya
0 1 0 9
asked 07 September, 2021
63 votes
2 answers
2K views
arrayfun can be significantly slower than an explicit loop in matlab. Why?

Consider the following simple speed test for arrayfun: T = 4000; N = 500; x = randn(T, N); Func1 = @(a) (3*a^

avatar
Yolando
0 1 0 9
asked 07 September, 2021
57 votes
5 answers
605 views
In MATLAB, when is it optimal to use bsxfun?

I've noticed that a lot of good answers to MATLAB questions on Stack Overflow frequently use the functio

avatar
Suzan
0 1 0 9
asked 07 September, 2021
61 votes
20 answers
3.1K views
Loop through an array of strings in Bash?

I want to write a script that loops through 15 strings (array possibly?) Is that possible? Something like: f

avatar
Venice
0 1 0 9
asked 07 September, 2021
57 votes
14 answers
1.7K views
How to update an "array of objects" with Firestore?

I'm currently trying Firestore, and I'm stuck at something very simple: "updating an array (aka a su

avatar
Stacia
0 1 0 9
asked 07 September, 2021
67 votes
12 answers
2.7K views
array_flip():Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()

I have recently migrated my module to Drupal7 (on PHP Version 5.3.1) and now I am getting following errors:

avatar
Robyn
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
1.2K views
How to convert array to SimpleXML

How can I convert an array to a SimpleXML object in PHP?

avatar
Carmelina
0 1 0 9
asked 07 September, 2021
60 votes
23 answers
2.8K views
How do I concatenate two arrays in C#?

int[] x = new int [] { 1, 2, 3}; int[] y = new int [] { 4, 5 }; int[] z = // your answer here... Debug.Asser

avatar
Suzan
0 1 0 9
asked 07 September, 2021
57 votes
6 answers
1.4K views
Numpy: Divide each row by a vector element

Suppose I have a numpy array: data = np.array([[1,1,1],[2,2,2],[3,3,3]]) and I have a corresponding "vector

avatar
Charis
0 1 0 9
asked 07 September, 2021
55 votes
8 answers
2.6K views
How to normalize a NumPy array to within a certain range?

After doing some processing on an audio or image array, it needs to be normalized within a range before it can

avatar
Basil
0 1 0 9
asked 07 September, 2021
56 votes
7 answers
1.9K views
NumPy array initialization (fill with identical values)

I need to create a NumPy array of length n, each element of which is v. Is there anything better than: a = e

avatar
Chaya
0 1 0 9
asked 07 September, 2021
55 votes
16 answers
1.5K views
numpy: most efficient frequency counts for unique values in an array

In numpy / scipy, is there an efficient way to get frequency counts for unique values in an array? Something

avatar
Xavier
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
598 views
How do I convert a numpy array to (and display) an image?

I have created an array thusly: import numpy as np data = np.zeros( (512,512,3), dtype=np.uint8) data[256,256

avatar
Tana
0 1 0 9
asked 07 September, 2021
53 votes
5 answers
2.6K views
What is the difference between ndarray and array in numpy?

What is the difference between ndarray and array in Numpy? And where can I find the implementations in the num

avatar
Majorie
0 1 0 9
asked 07 September, 2021
58 votes
6 answers
1.9K views
Concatenating two one-dimensional NumPy arrays

I have two simple one-dimensional arrays in NumPy. I should be able to concatenate them using numpy.concatenat

avatar
Hilario
0 1 0 9
asked 07 September, 2021
50 votes
7 answers
1.3K views
Comparing two NumPy arrays for equality, element-wise

What is the simplest way to compare two NumPy arrays for equality (where equality is defined as: A = B iff for

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
65 votes
6 answers
1.5K views
What is the difference between Numpy's array() and asarray() functions?

What is the difference between Numpy's array() and asarray() functions? When should you use one rather th

avatar
Louetta
0 1 0 9
asked 07 September, 2021
55 votes
15 answers
786 views
How do I create an empty array/matrix in NumPy?

I can't figure out how to use an array or matrix in the way that I would normally use a list. I want to c

avatar
Jefferey
0 1 0 9
asked 07 September, 2021