Loop through array for INSERT query parameters

So a INSERT query is like this: \$stmt = \$db->prepare("INSERT INTO table () VALUES ()"); I have an array here: \$array = ['a', 'aa', 'aaa', 'b', 'bb', 'sds', 'asdf', 'sdfswe', 'sdvsd', 'sdasss', 'sbdss', 'sdfabwew', 'asdfavs', 'sdbweq', 'sdfbs',...
more »

Plotting 3D image form a data in NumPy-array

I have a data file in NumPy array, I would like to view the 3D-image. I am sharing an example, where I can view 2D image of size (100, 100), this is a slice in xy-plane at z = 0. import numpy as np from matplotlib import pyplot as plt from mpl_toolk...
more »

numpy array with the second dimension empty

Although I have seen some answers for this question, I was wondering if there's any better way to solve this problem. For example, N = 15 A = np.repeat(1/N, N) if I do this the result will have shape (15, ) If I want the shape to be (15,1), I t...
more »

How to sort multidimensional array by name/timestamp?

I were using the "rsort" function to sort through the timestamps when the array only contained a timestamp and were not multidimensional. So now the question is how do i approach this? The array looks something similair to this Array ( [0] =&g...
more »

Initialise ArrayList<ArrayList<Int>> with a size in kotlin

I am trying to initialise a list with a size in the constructor. But the size of my list is 0. val seqList = ArrayList<ArrayList<Int>>(N) // This has the Problem val queries = ArrayList<Query>(Q) // This works like a charm I have...
more »

codewar challenge javascript

I hope everyone is having a good day. This is my first ever post on Stackoverflow! I have just completed the javascript course on codeacademy and have read a couple of books on it too. Now I am on codewars. I would classify myself as a beginner in ...
more »

How to Sort Array But Keep The Position of Duplicate Element in C?

So, actually what I need is to keep the index of old array after sorted. So for example if I input [2,4,1,5,7,9,6] then the output is [2,0,1,3,6,4,5]. I already have use qsort and it works very well if there are no duplicate elements. If there are d...
more »

How to use krsort() with an array of object?

I have an array of object like this : [0] => stdClass Object ( [id] => 527 [rate] => 0 ) [1] => stdClass Object ( [id] => 530 [rate] => 25 ) And i'm looking to sort it by rate in r...
more »

Storing an image dataset into 4D array then showing each image leads to distorted colors

I am trying to store an image dataset into a 4D ndarray then plot each image as follows: i=0 for j in imagelist: imageall[i] = misc.imread(j) ##(36, 570, 760, 3) plt.imshow(imageall[i]) plt.show() i=i+1 However, showing the image from the ...
more »

Cakephp hash extract parent_id null

Using array below i am trying to extract the id for vocabulary_id and null parent_id. Hash::extract(array, '{n}[vocabulary_id=9]') works Hash::extract(array, '{n}[vocabulary_id=9][parent_id=null') fails array( array( 'id' => 240,'parent_id' =>...
more »

Efficient solution for merging 2 sorted lists in Python

I am teaching my self Python by starting with the crash course published by Google. One of the practice problems is to write a function that takes 2 sorted lists, merges them together, and returns a sorted list. The most obvious solution is: def lin...
more »

Modifying array inside a function in C

// test.txt 50 13 124 - void hi ( int *b, FILE *pfile ) { rewind ( pfile ); int i; for( i = 0 ; i < 3 ; i++ ) { fscanf ( pfile, "%d", &b[i] ); } } int main ( void ) { FILE *fp = fopen ( "test.txt", "r" ); ...
more »

How can I assign instance of a class from an array to a class initializer in java?

In a Android application I am making I have an array of instances of a certain class I made, and later in the program I need to use the getter and setter methods from that class on an instance of the class from the array. Do I need to assign the inst...
more »

Unclear Javascript programming pattern (functions). Why the results differ?

Inside the Chrome Console I have a string: var string = 'john, john, bob, nina, colin, bob, luck, robert, nina, john, jack'; Then it is being modified and assigned to a new value using two, seeming identical to me, methods: First method: var str...
more »

convert numpy array to 0 or 1

A = np.array([[0.94366988, 0.86095311, 0.88896715, 0.93630641, 0.74075403, 0.52849619 , 0.03094677, 0.85707681, 0.88457925, 0.67279696, 0.26601085, 0.4823794 , 0.74741157, 0.78575729, 0.00978911, 0.9203284, 0.02453...
more »

expected 'double **' but argument is of type 'double (*)[2]'

I encountered this strange behavior in C. This code gives me the compile warning: expected 'double **' but argument is of type 'double (*)[2]' What is the problem? An array of doubles is a pointer to double, right? BTW, if I send the array itse...
more »

Subscript outside of limit

I tried several times in my cmd running this code but every time it says subscript out of limit at line 1 at the Declare but I haven't found any problem what should I do? declare type namesarray is varray(5) of varchar2(10); type grades i...
more »

mysqli_real_escape_string with array in php?

My code is like this public function addQuestions(\$data){ \$ans = array(); \$ans[1] = \$data['ans1']; \$ans[2] = \$data['ans2']; \$ans[3] = \$data['ans3']; \$ans[4] = \$data['ans4']; \$ans= mysqli_real_escape_string(\$this->db-&g...
more »

Compare two arrays of musical scale notes

I have two arrays — one representing the musical notes of a scale (in MIDI note numbers), and the other representing the user's raw input of notes recorded by an instrument. Both arrays are lists of Ints, representing musical notes. The scale arr...
more »

declare an array with unknown size without using ArrayList

Is there a way to declare an array with an unknown length? My problem is to return an int[] of odd integers from a range of numbers. My current output is adding 0s to fill up the remaining space of the array. public class Practice { static int[...
more »

Retrieve Values of Multiple Arrays with just an index

So I am trying to retrieve the value of multiple arrays given an index. So for example if I have three arrays 'one', 'two' and 'three' which have 12 values. My function getEvents(monthIndex: 0) will return: one[0], two[0], and three[0] in one array c...
more »

python How to replace the first f(x) values of each x in array(x,n)

I would like to replace the first x values in every row of my array a with ones and to keep all the other values NaN. The first x values however changes in every row and is determined by a list b. Since I'm not very familiar with arrays I thought I ...
more »

Pass variable from array into a function

I have this function: function getTotal () { var args = Array.prototype.slice.call(arguments); var total = 0; for (var i = 0; i < args.length; i++) { total += args[i]; } return total; } Lets say that I have an array...
more »

How to filter different keys in a array and get unique result in angular js

I'm trying to filter data from the response and remove duplicate items and push the data into an array, my api response goes as below: { "_id":"0", "yacht_id":"200", "promo_id":"300", "blocked_thru":"promotions", "dates":"2017-08-23T0...
more »

I have trouble with quicksort algorithm

I have problems with Quicksort algorithm. I have read on the internet about it on different pages, also Wikipedia. But they explained not too much in detail. I have understood their examples when you choose the very last element as pivotelement. In t...
more »

Get numbers divisible by a given divisor using logical operators in Python

I want to get a logical answer (TRUE/FALSE) whether the number from a list is divisible by a given divisor. This is the way I was doing it in R. array = (1:100) i = 3 sel <- !as.logical(array %% i) print(sel) The result looks like that : ...
more »

Post array and variable to view

I want to post an array and a variable to view. Here is my variable. \$ausgabeSpieltag = \$saisonMaxSpieltagEins; And here is my array and the way like I post it to view at the moment. But now I need additional the variable in the ->with part. \$spi...
more »

Get all elements from associative array and send them via POST method in PHP

I'm developing a simple contact form. I have an associative array \$_POST['hid']. Something like this: Array["0" => "Location0", "1" => "Location1", "2" => "Location2"] I'm trying to send this array as an email with a view on client side as: ...
more »

php need to sort arrays in array and get respective key

I need to sort the following multidimensional array in php and thereafter get the respective key of any array that I want: array:3 [▼ 0 => array:1 [▼ 4 => "404" ] 1 => array:1 [▼ 5 => "373" ] 2 => array:1 [▼ ...
more »

Python, Replace all array values with formatted string

I have a numpy array which is built of decimal hours like so: 13.1 13.2 13.3 13.4 14.1 14.2 14.3 14.4 15.1 15.2 15.3 15.4 What I wish to do is convert this array to a time string and then replace all the values in this array with a custom string f...
more »

JavaScript to split data and calculate sums

I believe what I need are two JavaScript functions. I am receiving a comma separated string that holds two types of data: 1) device name followed by 2) numeric value. These two values are separated by a comma, and each set is also separated by a comm...
more »

Swift generics and subclasses

my question might be simple, but it got me puzzled a bit: Imagine I have an array of different objects which all have a common parent class "MyClass". var values = [MyClass]() However they all have their specific subclass like for example "...
more »

Manipulating the constructor of a class in Java

I have an exercise about the analysis of passwords (weak vs strong) and I have to create 2 constructors. One of them must receive the length of a password and the password must be created randomly, how can I do that ? Also I'm having trouble determi...
more »

Faster alternative to numpy for manual element-wise operations on large arrays?

I have some code that was originally written in C (by someone else) using C-style malloc arrays. I later converted a lot of it to C++ style, using vector<vector<vector<complex>>> arrays for consistency with the rest of my project. I...
more »