arrays

how to improve this function that converts a flat array into a tree?

半世苍凉 提交于 2021-02-11 12:41:12
问题 I have this function that converts a flat array to a tree based on a path property. This is my data : const input = [ {"name":"brussels_district_north","path":"Brussels/Brussels CBD/North"}, {"name":"brussels_district_louise","path":"Brussels/Brussels CBD/Louise"}, {"name":"brussels_district_west","path":"Brussels/Brussels Decentralised/West"}, {"name":"brussels_district_léopold","path":"Brussels/Brussels CBD/Léopold"}, {"name":"brussels_district_airport","path":"Brussels/Brussels Periphery

passing variable through AJAX to PHP function getting undefined vairable but not understanding why the index is missing in the construct

让人想犯罪 __ 提交于 2021-02-11 12:41:06
问题 UPDATE - Wondering if it has to do with this line in the PHP function - $cid[] =''; I am getting the dreaded undefined index but even after reading SO answers about it, I am uncertain why the index isn't existing in my instance. I get that the index is missing which is why I see the error, I am not sure why the index is missing however. Is it the initial construction of the string that is causing the issue? Is it the way I am retrieving the $_POST['Cid'] ? When I var-dump I get the expected

how to improve this function that converts a flat array into a tree?

旧城冷巷雨未停 提交于 2021-02-11 12:40:21
问题 I have this function that converts a flat array to a tree based on a path property. This is my data : const input = [ {"name":"brussels_district_north","path":"Brussels/Brussels CBD/North"}, {"name":"brussels_district_louise","path":"Brussels/Brussels CBD/Louise"}, {"name":"brussels_district_west","path":"Brussels/Brussels Decentralised/West"}, {"name":"brussels_district_léopold","path":"Brussels/Brussels CBD/Léopold"}, {"name":"brussels_district_airport","path":"Brussels/Brussels Periphery

passing variable through AJAX to PHP function getting undefined vairable but not understanding why the index is missing in the construct

只愿长相守 提交于 2021-02-11 12:40:20
问题 UPDATE - Wondering if it has to do with this line in the PHP function - $cid[] =''; I am getting the dreaded undefined index but even after reading SO answers about it, I am uncertain why the index isn't existing in my instance. I get that the index is missing which is why I see the error, I am not sure why the index is missing however. Is it the initial construction of the string that is causing the issue? Is it the way I am retrieving the $_POST['Cid'] ? When I var-dump I get the expected

How to center the nonzero values within 2D numpy array?

此生再无相见时 提交于 2021-02-11 12:35:04
问题 I'd like to locate all the nonzero values within a 2D numpy array and move them so that the image is centered. I do not want to pad the array because I need to keep it the same shape. For example: my_array = np.array([[1, 1, 0, 0], [0, 0, 2, 4], [0, 0, 0, 0], [0, 0, 0, 0]]) # center... >>> [[0 0 0 0] [0 1 1 0] [0 2 4 0] [0 0 0 0]] But in reality the arrays I need to center are much larger (like 200x200, 403x403, etc, and they are all square). I think np.nonzero and np.roll might come in handy

How to center the nonzero values within 2D numpy array?

六月ゝ 毕业季﹏ 提交于 2021-02-11 12:34:11
问题 I'd like to locate all the nonzero values within a 2D numpy array and move them so that the image is centered. I do not want to pad the array because I need to keep it the same shape. For example: my_array = np.array([[1, 1, 0, 0], [0, 0, 2, 4], [0, 0, 0, 0], [0, 0, 0, 0]]) # center... >>> [[0 0 0 0] [0 1 1 0] [0 2 4 0] [0 0 0 0]] But in reality the arrays I need to center are much larger (like 200x200, 403x403, etc, and they are all square). I think np.nonzero and np.roll might come in handy

Python/PyTables: Is it possible to have different data types for different columns of an array?

耗尽温柔 提交于 2021-02-11 12:33:29
问题 I create an expandable earray of Nx4 columns. Some columns require float64 datatype, the others can be managed with int32. Is it possible to vary the data types among the columns? Right now I just use one (float64, below) for all, but it takes huge disk space for (>10 GB) files. For example, how can I ensure column 1-2 elements are int32 and 3-4 elements are float64 ? import tables f1 = tables.open_file("table.h5", "w") a = f1.create_earray(f1.root, "dataset_1", atom=tables.Float32Atom(),

Delete object from array in c++

拟墨画扇 提交于 2021-02-11 12:32:32
问题 Fruits class: #include <string> using namespace std; class Fruits { string color; public: Fruits() { color = "r"; } }; Main: #include "Fruits.cpp" void main() { Fruits* fruits[6]; fruits[0] = new Fruits(); // delete[] fruits[0]; // <-- does not work (deletes one object) // delete[] fruits; // <-- does not work (deletes all objects in the array) } How can I do this? 回答1: delete fruits[0] will delete that one object for you. delete[] instead serves to delete all non-null elements of that array,

c++ getline() looping when used in file with a read in int array?

浪尽此生 提交于 2021-02-11 12:27:46
问题 So I posted this the other day with not enough information and never got an answer once I added the information asked, so I can't get the loop to work so my question is, I am reading from a file that has large text of strings on each line, it then has ints on the next line the strings need to be read into questionArrays() and the ints into answersArrays. Currently the loop simply goes round once and then just loops as it doesn't get any further in the file on the next getline() I did have

what is array decay in c and when it happen?

折月煮酒 提交于 2021-02-11 12:19:26
问题 I am currently studying C language. I wonder what 'array decaying' means, and when it happens. And I wonder if the two variables below are interpreted in the same way. char(*zippo)[2] = NULL; char zippo2[4][2]; zippo = (char(*)[2])malloc(sizeof(char[2]) * 4); 回答1: From the C Standard (6.3.2.1 Lvalues, arrays, and function designators) 3 Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type