state gets updated before setState is called

lifeParser is a method called to process and update boardData. The problem is boardData gets updated while the loop is still processing. lifeParser(){ var parseArray = this.state.boardData.slice(0); for(var i=0;i<30;i++){ for(va...
more »

2017-04-20 04:04 (2) Answers

Select 'some' random points from numpy array

I have two related numpy arrays, X and y. I need to select n random rows from X and store this in an array, the corresponding y value and the appends to it the index of the points randomly selected. I have another array index which stores a list of...
more »

2017-04-20 01:04 (2) Answers

reversing an array in javascript

I have a Javascript function called reverseArray that takes an array as the argument and returns a new array which has the same values as the input array in reverse order. I want to create a function called reverseArryInPlace which would change the v...
more »

2017-04-19 06:04 (5) Answers

Write dynamical arrays in Fortran 90

I have arrays with dynamical dimension (dimx, dim) and I need a way to write such arrays in a file through the Write instruction, the problem is that until now I haven't been able to produce such files in a automatic way, I mean until now I have to c...
more »

2017-04-19 00:04 (2) Answers

Array slicing with booleans as indices

Can someone explain this syntax to me? I've searched through docs/blogs but can't find any mention of using booleans as indices for array slicing. I found this syntax in this script convert_base.py: is_negative = num_as_string[0] == '-' num_as_str...
more »

2017-04-18 23:04 (2) Answers

Using an array for functions in javascript

I'm trying to create a program that uses an array of functions to cycle through the order of execution. I've included the program below, can somebody please suggest what i have done wrong.I have created a set of traffic lights on HTML and im trying t...
more »

2017-04-18 15:04 (4) Answers

Mutating an array without extra space

I was given the following question in an interview, and couldn't find the solution. Given is an array of chars length n, and "important section" (all chars in this section must be saved) length m where n >= m >= 0 as follows: Without extra space...
more »

2017-04-18 15:04 (3) Answers

Convert PHP Array to JSON Array of object

I'm using Google Orgchart in my project. In that I'm returning JSON OBJECT from PHP file. Problem My Problem is when I hardcode the value, It works fine. When I return data from PHP file. It did not work. I guess the data format which is returning ...
more »

2017-04-18 08:04 (3) Answers

Find element that appears odd number of times

I'm trying to solve this exercise of finding the number that appears an odd number of times in an array. I have this so far but the output ends up being an integer that appears an even number of times. For example, the number 2 appears 3 times and th...
more »

2017-04-18 00:04 (4) Answers

How to sum columns of an array in Python

How do I add up all of the values of a column in a python array? Ideally I want to do this without importing any additional libraries. input_val = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]] output_val = [3, 6, 9, ...
more »

2017-04-17 23:04 (9) Answers

R searching for information within column

I have two tables. Which have the kind of formatting shown below. One of it is table A as such: students|Test Score A | 100 B | 81 C | 92 D | 88 Another table B I have looks like this: Class | Students 1 | {A,D}...
more »

2017-04-17 23:04 (5) Answers

Loading .npy File Loads an Empty Array

I have a TfIDF matrix of size tr_tfidf_q1.shape, tr_tfidf_q2.shape which gives ( (404288, 83766), (404288, 83766) ) Now I save it using np.save('tr_tfidf_q1.npy', tr_tfidf_q1) When I load the file like this f = np.load('tr_tfidf_q1.npy') f...
more »

2017-04-17 18:04 (2) Answers

How to Iterate uploaded image files

I want to use foreach() to move image files into a folder and print imageupload name, tmp_name and so on. I am working on zend. Input array: Array ( [imageUpload] => Array ( [name] => P_20170224_134956_BF.jpg ...
more »

2017-04-17 11:04 (1) Answers