Posts

Showing posts with the label arrays

How can I find closest date value from an array according to the current date?

How can I find closest date value from an array according to the current date? I want to get the next closest date on this array according to the current date. var dates = [ 'Aug 18, 2018 03:24:00', 'August 19, 2018 03:24:00', 'September 17, 2018 03:24:00', 'September 14, 2018 03:24:00', 'August 18, 2018 03:24:00', 'July 16, 2018 03:24:00', 'July 15, 2018 03:24:00', 'December 15, 2018 03:24:00', 'July 13, 2018 03:24:00', ]; var now = new Date(); 4 Answers 4 First you need to convert each date into a timestamp then subtract each of them by the current date and store the timestamp difference in the temp array then get the index of the minimum value and use the index to access the closest date in the original array. var dates = [ 'July 16, 1995 03:24:00', 'Aug 18, 1995 03:...

convert data string from numpy array to int python

convert data string from numpy array to int python I have a string Numpy array in Python 3 like this Numpy array, array[['(155)'],['(255)'],['(165)'],['(147)']] I need to convert this one to int Numpy array, like this, array[[115],[255],[165],[147]] 1 Answer 1 Strip 'em and parse 'em: np.core.defchararray.strip(a, '()').astype(int) thank you very much, I am a beginner in python – Santiago molina sanchez Jun 30 at 1:00 You can replace np.core.defchararray with np.char . – Abhishek Mishra Jun 30 at 1:16 np.core.defchararray np.char ...

Need Help populating array with JSON data using SwiftyJSON

Need Help populating array with JSON data using SwiftyJSON I want to populate an array I have with JSON data. I'm using SwiftyJSON and Alamofire. I'm new to parsing JSON, so i apologize for any ignorance on my end. The URL below is the url i'm inserting in getAllTimeAverage(). Any help would be awesome!! thanks! This is the JSON Data https://apiv2.bitcoinaverage.com/indices/global/history/BTCILS?period=alltime&format=json This is the array i want to populate var allTimeAverages: [Any] = These are my functions. I call them in my cellForRowAt:, when i print the allTimeAverages.count, I get back zero. func getAllTimeAverage(url: String) { Alamofire.request(url, method: .get) .responseJSON { response in if response.result.isSuccess { print("Sucess! Got the Bitcoin Data") let bitcointJSON : JSON = [JSON(response.result.value!)] self.updateAverageAllTime(json: bitcointJSON) } else {...

javascript insert object to array at specific point id and increment others id

javascript insert object to array at specific point id and increment others id I have little problem with js arrays. I want to insert object on if statement and increase id on anothers objects var arr=[{asc_id:1, date:2018-06-29, name:"first"}, {asc_id:2, date:2018-06-30, name:"second"}, {asc_id:3, date:2018-07-10, name:"fourth"}, {asc_id:4, date:2018-07-10, name:"fifth"}]; var checkedItem={asc_id:4, date:2018-06-30, name:"third"}; let savingDate = moment(checkedItem.date) var newArr = arr.map((item,key)=>{ if(savingDate.isSame(item.date) || savingDate.isAfter(item.date)){ console.log(true) return{ //code here } }else{ return{ //code here } console.log(false) } }) console.log(newArr) i want make new array looks like newArr=[{asc_id:1, date:2018-06-29, name:"first"}, {asc_id:2, date:2018-06-30, name:"second"}, {asc_id:3, date:2018-0...

Check if certain stings (even with spaces) are in array

Check if certain stings (even with spaces) are in array Trying to compare two arrays and see if existing words (even with spaces) exists in both. See below. I think I have a rough idea. Thanks ahead for your help! HTML <meta name="keywords" content="dog, cat, humming bird, shark, king cobra"> Jquery var myArray = $("meta[name='keywords']").attr("content"); var myAnimals = ["humming bird","king cobra"]; if (jQuery.inArray(myAnimals, myArray) != -1) { alert('animal exists'); } Possible duplicate of Check if an array contains any element of another array in JavaScript – Mike McCaughan Jun 29 at 17:50 4 Answers 4 attr("content") will return a string. You can use ...

remove a character from a data numpy array

remove a character from a data numpy array I am currently importing a .txt file to a numpy array. The .txt file is organized by three columns with hundreds of thousands of rows. Occasionally, for no apparent reason, the third column will have a attached to the number. This causes genfromtxt to import the number as nan . I have tried using a replace function for numpy , but I believe this function is looking for a string because I get an "EOL while scanning string literal" error code.enter image description here numpy genfromtxt nan numpy Any advice? import numpy as np import numpy.core.defchararray as np_f FLR = np.genfromtxt("C:UsersbrandDownloadsPythonMyFilesaupnipam_scan41_3DFLR.txt") FLR = np_f(FLR, '', '') x = FLR[:,][:,0] y = FLR[:,][:,1] z = FLR[:,][:,2] I've added a picture of what the raw data looks like to show what I mean by it having a "" in the data Following is the complete error code I get File "<ipython-...

Intersect between two arrays of objects and keep only matched element and delete the non-matching element based on key of object

Intersect between two arrays of objects and keep only matched element and delete the non-matching element based on key of object I have two arrays of objects and I need to intersect between the arrays to find out the common one and delete it from the first array which does not have the same item based on one of the keys. Note that I want to mutate the first array itself. Here is my code sample and what I tried with .map but did not get the expected result. .map (() => { const first = Array.from({ length: 5 }, (_, i) => ({ id: `in-${i}`, name: "one", age: `${i * 5}` })); const second = Array.from({ length: 3 }, (_, i) => ({ id: `in-${i}`, name: "two" })); console.log({ first }); console.log({ second }); const sid = second.map(s => s.id); first.map((f, i) => { if (sid.includes(f.id)) { console.log("✔️ included"); } else { console.log("👎🏻 not included"); first.splice(i, ...

Grouping neighbouring entries with the same value in a 2d array

Grouping neighbouring entries with the same value in a 2d array EDIT: I now realized the question was not appropriate for stack but I've gotten a lot of helpful advice anyway. Thanks everyone! I have a 2d array and I want to group together neighbors of the same value. Using C# (working with unity). Let's say I have this: int[,] array { 0,0,0,0,0,0,1,0,0,0, 0,1,1,0,0,0,1,0,0,0, 0,1,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,1,1,1,0, 0,0,0,0,0,0,1,1,1,0 } There are three "clusters" of 1:s. I want to add them to a dictionary with some variable for identification. So maybe first add the neighboring values to a list, add that list to a dictionary, clear the list and move onto the next cluster. The columns and rows would be of equal length in the real thing. I would also want the sorting method to accept arrays of various sizes so no hardcoded values. I parse the array from an XML document. I've tried looking into Array.Sort but the resources I have fou...

How To Split Array Of Data in Swift

How To Split Array Of Data in Swift I am Getting the array of Data from Remote Server which is as follow var i :[Data] = myImageData as [Data] which is printing as follow var i is --- > [4927 bytes, 5945 bytes, 7556 bytes] and I want to remove Braces , I want to get list like this var i is --- > 4927 bytes, 5945 bytes, 7556 bytes Have you checked this? stackoverflow.com/questions/32074136/… – TheNitram Jun 29 at 16:08 @TheNitram its Splitting String , Not [Data] – Rishabh Shukla Jun 29 at 16:10 Something like that: let dataAraryDescription = myImageData.map({ String($0.description)}) joined(separator:", ") ? You might event ...

How to sort data coming from the API by date in Angular 4

How to sort data coming from the API by date in Angular 4 This is the JSON data i am fetching from POSTMAN. I want it to be ordered in a nearest to todays date. I tried many angular pipes but unfortunately nothings working. Any help would be great. I want to sort the date by the "broadcastOn" field. Thanks in advance. [ { "messageId": "09ca0609-bde7-4360-9d3f-04d6878f874c", "broadcastOn": "2018-02-08T11:06:05.000Z", "message": "{"title":"Server Side Test 2","text":"Different Message again","image":"https://api.adorable.io/avatars/285/abott@adorable.png","url":"https://www.google.co.in"}" }, { "messageId": "0a5b4d0c-051e-4955-bd33-4d40c65ce8f7", "broadcastOn": "2018-02-08T10:36:27.000Z", "message": "{"title":"Broadc...

Resize array in C# later in the program

Resize array in C# later in the program I am not sure if this is possible in c# but i'm having a variable defined in public partial class Form1 : Form {... ... #region used variables public ulong logP = {0,0,0,0,0,0,0,0} .... .. Then later in the program i want have an option to adjust the size in the program before the main routines will launch over it and do some calculations Because i like to test with vaious sets of numbers and array sizes i would like to have an option to resize the array, for each test (but this array isnt bound to a single procedure, its a global variable that needs to be resizable. As the whole program at various parts is using this array, (under various functions) how should i put this part ulong sumP = new ulong[numericupdown.valeu]; So that it would change this global variable size ? why dont you use a List<ulong> ? – Daniel A. White Oct 11 '13 at 22:29 ...

Why does C support negative array indices?

Why does C support negative array indices? From this post in SO, it is clear that C supports negative indices. Why support such a potential memory violation in a program? Shouldn't the compiler throw a Negative Index warning at least? (am using GCC) Or is this calculation done in runtime? EDIT 1: Can anybody hint at its uses? EDIT 2: for 3.) Using counters of loops in of arrays/pointers indicates Run-time Calculation of Indices. You can legitimately take the address of the Nth element of an array and then negatively index down to -N. – Hot Licks Aug 11 '13 at 14:20 @ 1) : to avoid negative indexing you can use unsigned types as an index, which also has the nice property of failing fast . – wildplasser Aug 11 '13 at 14:29 ...