Questions tagged [arrays]

104791 questions
1

votes
4

answer
67

Views

What is the best way to print all the dates contained on some objects dates ranges inside an array?

If I have an array of objects like this: { 'workPeriods': [ { 'user_id': '9345bf', 'startDate': '2018-02-05T05:00:00.000Z', 'endDate': '2018-02-09T05:00:00.000Z' }, { 'user_id': '80c3a9', 'startDate': '2018-02-12T05:00:00.000Z', 'endDate': '2018-02-16T05:00:00.000Z' }, { 'user_id': '35jh87', 'startD...
Leonardo Uribe
1

votes
0

answer
36

Views

Vectorize quintuple for loop in numpy, with non-trivial indexing

I have a series of nested for loops, used to populate a rank-3 array as follows: S = ... # Some number N = ... # Some other number an_array = np.zeros((S, N * N, N * N)) for s in range(S): for i in range(N): for a in range(N): for j in range(N): for b in range(N): an_array[s, i * N + a, j * N + b]...
Daniele Grattarola
1

votes
0

answer
56

Views

Array filtration of String with contains is slow

searching text from an array of Product, but data is huge, and stuck ui view and keyboard. func searchText(text: String) -> [Product]{ self.filterData = text.isEmpty ? self.productCollection : self.productCollection.filter({(product: Product) -> Bool in // If dataItem matches the searchText, ret...
Ayaz Akbar
1

votes
2

answer
49

Views

Summarize the same key name in php multidimensional array

I have an array like this: [0] => Array ( [id_station] => 2397 [hour] => 12 [data] => Array ( [cameraon] => 355654 [cameraoff] => 4532 [camerabroken] => 76745 ... ) ) [1] => Array ( [id_station] => 2399 [hour] => 13 [data] => Array ( [cameraon] => 3905466 [cameraoff] => 1672 [camerabroken] => 70780...
sontd
1

votes
0

answer
117

Views

Loop through Dictionary in Swift

I have a dictionary which I want to append some items. **This is my dictionary which I want to achieve: ** let parameters: [String: Any] = [ { 'ResultsList': [{ 'UserId': 'b806e283-066f-4081-aafe-1fe216a57c35', 'FriendUserId': '7a2ec150-cdb3-4600-84f8-2dab970bfa0c', 'TransferDate': '2017-11-23', 'U...
Ziyaad
1

votes
1

answer
51

Views

how to compare n multiple sentences which are in array and get the common words using php using array_intersect and store the common words in an array

Hi friends am trying to compare n sentences in an array and get the common words which are present in more than one sentence. Here is sample $cars=('hello how','hello when','when you came',........,n sentences); array_intersect is used to compare 2 or 3 arrays which have exactly common words in all...
Shruti
1

votes
1

answer
23

Views

Maximum executiontime exceeded when printing array

I have the following code, which prints all combinations of the given numbers. It returns a fatal error when $numbers contains two equal numbers. I get the following error: Fatal error: Maximum execution time of 30 seconds exceeded in C:/Apache24/htdocs/index.php on line 18 My Code:
Paweł Tymecki
1

votes
1

answer
180

Views

Numpy arrays from tuples of arrays for matrix based neural networks

To implement learning in a neural network I'm using stochastic gradient descent in which the mini batches are represented via the following list comprehension: mini_batches = [training_data[j:j+mini_batch_size] for j in range(0,len(training_data),mini_batch_size)] Inside the list comprehension the s...
sunspots
1

votes
3

answer
58

Views

Compare multiple array values and return keys of duplicates

SOLUTION $hours = array( 'Mo' => array('open' => true, 'from' => '10:00', 'to' => '20:00'), 'Tu' => array('open' => true, 'from' => '10:00', 'to' => '18:00'), 'We' => array('open' => true, 'from' => '10:00', 'to' => '20:00'), 'Th' => array('open' => true, 'from' => '10:00', 'to' => '18:00'), 'Fr' =>...
AJ 21
1

votes
1

answer
45

Views

JSON post returning null when passed from view to controller

vm.Name returns null when it's passed from view to controller but when I call for the data in view, it shows up fine. $scope.afterSelectedIngredient = function (selected) { if (selected) { $scope.selectedIngredient = selected.originalObject; $scope.newIngs = []; var ing = {}; ing.Name = $scope.selec...
klent
1

votes
1

answer
46

Views

NSKeyedUnarchiver results in nil values after transfer via MFMailComposeController

I am sending a keyed archive as an attachment to an email using MFMailComposeController. My app that reads the email attachment gets the keyed archive but unarchiving it gives nil values. Details as follows: The sending view controller: - (IBAction)saveAndSend:(id)sender { // Email Subject NSString...
Nelson Capes
1

votes
0

answer
43

Views

C++ overloaded [] operator with sorted array

I have class called Vector which contains dynamic array with numbers. But array must be always sorted. I have a few methods like changeSize, addElement, etc. but the only problem is overloaded array operator. It must return particular number to read or write. This is my code: double &Vector::operato...
Atof
1

votes
5

answer
63

Views

Create new array based on array index

I have an array as follows [ 'test123', '', 'testabc' ] How can i make an array based on the array index of this array.My desired output is [ '1', '0','1']. If any element is there in the index it should give 1 otherwise 0. What is best way to generate an array like this in nodejs.
Anuja vinod
1

votes
3

answer
40

Views

Split the string array

I know this question was absolutely answered but i did not find solution. I get response from web-service a Json string response that is ['11,22222','33,44444']. I try this but did not work because string include these characters [ ] and first comma is in the here 11,22 StringBuilder result = new St...
1

votes
1

answer
53

Views

dtype of ndarray containing string in python

I know that in case of ndarray containing strings, dtype returned will be of the form dtype(S#) where # denotes the length of the string. As shown in figure the array 'a' which is generated from a list [1,'2','3']. Once the array is created all the elements become string type. Array 'b' is created...
Sharon
1

votes
1

answer
426

Views

How to display an array in a label

How do I display an array/the elements of an array in a label? I'm updating the elements each time so they will change from underscores to letters as more buttons are pressed in a game of hangman. 'random' is the animal randomly generated from a different array. if random == 'aardvark' { theWord.te...
user9154815
1

votes
1

answer
103

Views

React-redux: Nested array is being duplicated

I'm trying to create an order table (array) that has a nested 'products' array in each order. The order table is rendering as expected, but the products are the same for every order. OrderTable Component (simplified for clarity) class OrderTable extends Component { componentWillMount() { this.props....
Ash
-1

votes
2

answer
30

Views

How to find maximum negative and minimum positive number in a numpy array?

I am given an array containing both positive and negative numbers. import numpy as np arr = np.array([-10.2, -5.3, -2.1, 0, 1.2, 3.4]) I would like to find the index corresponding to the maximum negative number and to a minimum positive number. In the above, my expected outcome is 2 and 4. Is there...
matttree
1

votes
2

answer
47

Views

Convert last characters of std::array<char, 10> to int

Given the following array: std::array stuff I'd like to convert the last 4 characters to the corresponding int32 value. I tried to chain OR operations on the last items but doesn't seem to be the right way: int a = int(stuff[6] | stuff[7] | stuff[8] | stuff[9]) Is there an elegant way to solve this?
Kyu96
5

votes
1

answer
30

Views

Python partitioning an N-dimensional volume into uniform sub-volumes

I have an N-dimensional square grid (represented by a numpy array) from which I need to get the coordinates of the vertices of all the 1x1x1x... N-cubes (i.e., hypercubes). For each 1x1x1x... N-cube, I need to store the 2^N coordinates (grid points) of the vertices in a numpy array for further proce...
ooter
1

votes
0

answer
72

Views

How is changing array dimension exempted from strict alias rules?

Does the standard allow us to reinterpret dimension of array (while maintaining the underlining type, of course) template auto& arr_reinterp(T& arr1d) { using U = std::remove_reference_t; return reinterpret_cast(arr1d); // U(&)[M][N], ironically UB in this case? } just to use it like this? char a[10...
sandthorn
1

votes
0

answer
44

Views

Camera2, Images get saved to gallery as blank images with exclamation mark

Don't know why it's doing this, here's my code, maybe I did something wrong and don't realize it? private final ImageReader.OnImageAvailableListener mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() { @Override public void onImageAvailable(ImageReader reader) { mBackgroundHandle...
iBEK
1

votes
2

answer
76

Views

Incrementing Array Index on button click in Javascript

Below is my javascript code! I'm trying to increment the index of array $arr everytime the user clicks a button. The array is defined in a separate php tag! Where am I going wrong? function option1() { var i = 0; document.getElementById('btn0').value = 'newButtonValue'; document.getElementById('ques...
Zaid Waseem
1

votes
2

answer
44

Views

Rails: why can I send a single record attribute via controller to new record but not array?

Creating articles via the controller in Rails. A simple method, which more or less works; just call the method from some other place and it generates a new article via the back end and fills in the values: def test_create_briefing a = Article.new a.type_id = 27 a.status = 'published' a.headline = 'T...
Matthew Bennett
1

votes
2

answer
51

Views

I am having trouble char array in java

I wrote this code. My aim is to write the string in char. But i'm getting ArrayIndexOfBoundsException error. public class Charwork { char[] letter; int keepInt; public Charwork() { letter = new char[keepInt]; } public void copy(String nameToCoppy) { this.keepInt = nameToCoppy.length(); System.out.p...
forevl111
1

votes
1

answer
749

Views

How to return a file using byte [] with web Api?

I trying export file with web Api. this is my client code : exportLicense(licenseIds) { return this.$http({ method: 'POST', contentType: 'application/zip', url: this.application.resolveWebApiService('Licenses', 'ExportLicenses'), data: licenseIds }); } ExportLicenses method from my backend side(my...
eagle
1

votes
0

answer
122

Views

I have this error and i don't understand why: int' object is not subscriptable

This is my code (a small part of it but you have here all is neccesaire for understanding the error i think). Also, my code should apply the DELTA RULE import numpy as np import random y = np.array([[ 45, 85, -1], [ 50, 43, -1], [ 40, 80, -1], [ 55, 42, -1], [200, 43, -1], [ 48, 40, -1], [195, 41, -...
Bianca Trifanescu
1

votes
1

answer
69

Views

multidimensional array of objects in angular

I have a multidimensional array of an object in angular 2 declared in my class as follow: export class MatrixComponent implements OnInit { private columnsNumber: number = 10; private linesNumber: number = 10; private grid: SquareComponent [][]; constructor() { this.grid = []; var square = new Square...
Bonomi
1

votes
0

answer
958

Views

Convert json Array to Object on Vue Js 2

I'm trying to convert my data json from an array to an object to be able to consume the data but something went wrong... Here is the data json sample: [ { 'id': 1, 'title': 'my title', 'imgHero': '../../path/hero.jpg' } ] And here is the Vue component: {{ blog.title }} import tripsJson from '@/data/...
BeeLee
1

votes
2

answer
271

Views

Python: How to pass subarrays of array into array function

The ultimate goal of my question is that I want to generate a new array 'output' by passing the subarrays of an array into a function, where the return of the function for each subarray generates a new element into 'output'. My input array was generated as follows: aggregate_input = np.random.rand(1...
Michael D
1

votes
0

answer
538

Views

Iterate through nested arrays in native-base and display the content on multiple lines using List

I am quite new to react-native and native-base. I would like to access 'description' inside the data array in below JSON response using List in React-Native and display them as different ListItems. JSON file(data.js): [ { object: 'list', data: [ { id: 'cust1', object: 'customer', account_balance:...
Divya R
1

votes
0

answer
31

Views

Create a nested array of comments

I am currently creating a little WordPress-import-script using PHP. This is a part of my XML input: 1 [email protected] http://this-is-a-test.wordpress.com 134.76.4.169 2017-12-21 11:23:31 2017-12-21 09:23:31 1 0 132023990 2 [email protected] http://this-is-a-test.wordpress.com 134.76.4.169 2017-12-21...
SPQRInc
1

votes
0

answer
32

Views

how to create list of given values in “a” usig python?

I have written a code which will give maximum value from all arrays.I want to store all these values in a single list but i am getting different lists of different values. how to create a single list of these values? import numpy as np import re import gdal import ogr from osgeo import gdal_array fr...
vigna purohit
1

votes
1

answer
262

Views

Move an element from one array to another within same document MongoDB

I have data that looks like this: { '_id': ObjectId('4d525ab2924f0000000022ad'), 'array': [ { id: 1, other: 23 }, { id: 2, other: 21 }, { id: 0, other: 235 }, { id: 3, other: 765 } ], 'zeroes': [] } I'm would like to to $pull an element from one array and $push it to a second array within the same d...
Robert Ricketts
1

votes
1

answer
88

Views

Comparing array elements and style.fontFamily

I'm working on developing a text font game where the user guesses the font displayed on the screen, however an issue arises when I try to compare the style.familyFont of the text clicked and the corresponding array element font. After doing some tests, it appears that the console prints out false wh...
Rahul Sharma
1

votes
0

answer
60

Views

My code for creating new numbers with different digits from an 2D array sometimes doesn't work properly [duplicate]

This question already has an answer here: Why does pow(n,2) return 24 when n=5, with my compiler and OS? 5 answers Why is my integer math with std::pow giving the wrong answer? 5 answers I am beginner in C++ and I am creating a cows and bulls(player) program. The program works by making a 2D boole...
Drago Nikolov
1

votes
1

answer
64

Views

Variable keeps turning into an object instead of an Array in Javascript

I'm learning javascript (and HTML on Electron), and I have a variable which is meant to be an array: var arrayList = []; When I add objects to it (taken from JSON data), using Push: arrayList.push(object); Everything works perfect. I then save this using an api from npm called: electron-json-storage...
testuser111
1

votes
1

answer
63

Views

Having trouble displaying contacts with special characters on TableView

I've got a problem populating my table view. Currently, I'm creating a phone book. This phone book will simply contain contacts that are fetched with the help of the Contacts framework. These contacts are separated into sections alphabetically. Sadly, although my contacts are well displayed alphabe...
1

votes
4

answer
99

Views

Loop notification to every user

I'm trying to send a notification to every users thats assigned to a project. I can get all user id by doing this $ids = array_column($users, 'id'); $userid = implode(', ', $ids); echo $userid; But when I trying to put it insida my function nothing happened. It just blank. I have also tried to move...
Fredrik J
1

votes
0

answer
93

Views

IndexOutofBound, No Line number shown for error

I am newbie in android, I don't know why i am getting following error. I have tried every possible solution but doesn't work for me. It doesn't show any line number where actual error is occurring. I have tried with different methods and solution, With another way when i try with adapter and other...
user3686177

View additional questions