array

How do I split a string on a delimiter in Bash?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this string stored in a variable: IN="bla@some.com;john@home.com" Now I would like to split the strings by ; delimiter so that I have: ADDR1="bla@some.com" ADDR2="john@home.com" I don't necessarily need the ADDR1 and ADDR2 variables. If they are elements of an array that's even better. After suggestions from the answers below, I ended up with the following which is what I was after: #!/usr/bin/env bash IN="bla@some.com;john@home.com" mails=$(echo $IN | tr ";" "\n") for addr in $mails do echo "> [$addr]" done Output: > [bla@some.com] >

Rotate an YUV byte array on Android

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm looking to rotate a YUV frame preview recieved from a Preview Callblack, so far I've founded this post which cointains an algorithm to rotate the frame preview but is messing the preview image camera pixels rotated another way to rotate the image will be creating a jpg out of the YUV image, create a bitmap, rotate a bitmap and obtaining the byte array of the bitmap, but I really need the format in YUV (NV21). FYI. the reason I'm asking this is because I have a camera app that supports rotation, but the frame previews are coming back in

What would cause an algorithm to have O(log n) complexity?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My knowledge of big-O is limited, and when log terms show up in the equation it throws me off even more. Can someone maybe explain to me in simple terms what a O(log n) algorithm is? Where does the logarithm come from? This specifically came up when I was trying to solve this midterm practice question: Let X(1..n) and Y(1..n) contain two lists of integers, each sorted in nondecreasing order. Give an O(log n)-time algorithm to find the median (or the nth smallest integer) of all 2n combined elements. For ex, X = (4, 5, 7, 8, 9) and Y = (3, 5,

Insert a new record if not exist and update if exist, laravel eloquent

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there any shorthand for us to insert a new record if doesn't exist and update the record if exist? the following is the code i using. $shopOwner = ShopMeta::where('shopId', '=', $theID)->where('metadataKey', '=', 2001)->first(); if ($shopOwner==null){ insert new record into database } else { update the existing record } Thanks 回答1: Here's a full example of what "lu cip" was talking about: $user = User::firstOrNew(array('name' => Input::get('name'))); $user->foo = Input::get('foo'); $user->save(); Docs here: http://laravel.com/docs

Saving a Numpy array as an image

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a matrix in the type of a Numpy array. How would I write it to disk it as an image? Any format works (png, jpeg, bmp...). One important constraint is that PIL is not present. 回答1: You can use PyPNG . It's a pure Python (no dependencies) open source PNG encoder/decoder and it supports writing NumPy arrays as images. 回答2: This uses PIL, but maybe some might find it useful: import scipy.misc scipy.misc.imsave('outfile.jpg', image_array) EDIT : The current scipy version started to normalize all images so that min(data) become black and

jquery array group by

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have array like this abcArr = [["A", 10], ["B", 20], ["A",30],["C",40]] how can I group and sum values by A, B, C... $.each(abcArr , function() { if (this[0] == this[0]) { this[1] + this[1] }; // I know this will simple double [1] values :( }); desired result should be [["A", 40], ["B", 20], ["C",30]] 回答1: Here's a plain javascript way to do it that collects the unique indexes in a map and totals them as it does, then regenerates the array with the totals: abcArr = [["A", 10], ["B", 20], ["A",30],["C",40]]; var items = {}, base, key; for

Conversion between UTF-8 ArrayBuffer and String

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an ArrayBuffer which contains a string encoded using UTF-8 and I can't find a standard way of converting such ArrayBuffer into a JS String (which I understand is encoded using UTF-16). I've seen this code in numerous places, but I fail to see how it would work with any UTF-8 code points that are longer than 1 byte. return String.fromCharCode.apply(null, new Uint8Array(data)); Similarly, I can't find a standard way of converting from a String to a UTF-8 encoded ArrayBuffer . 回答1: function stringToUint(string) { var string = btoa

How to find index of all occurrences of element in array?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to find the index of all the instances of an element, say, "Nano", in a JavaScript array. var Cars = ["Nano", "Volvo", "BMW", "Nano", "VW", "Nano"]; I tried jQuery.inArray , or similarly, .indexOf() , but it only gave the index of the last instance of the element, i.e. 5 in this case. How do I get it for all instances? 回答1: The .indexOf() method has an optional second parameter that specifies the index to start searching from, so you can call it in a loop to find all instances of a particular value: function getAllIndexes(arr,

Finding the nearest value and return the index of array in Python

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I found this post: Python: finding an element in an array and it's about returning the index of an array through matching the values. On the other hand, what I am thinking of doing is similar but different. I would like to find the nearest value for the target value. For example I am looking for 4.2 but I know in the array there is no 4.2 but I want to return the index of the value 4.1 instead of 4.4. What would be the fastest way of doing it? I am thinking of doing it the old way like how I used to do it with Matlab, which is using the

How to normalize an array in NumPy?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to have the norm of one NumPy array. More specifically, I am looking for an equivalent version of this function def normalize(v): norm = np.linalg.norm(v) if norm == 0: return v return v / norm Is there something like that in skearn or numpy ? This function works in a situation where v is the 0 vector. 回答1: If you're using scikit-learn you can use sklearn.preprocessing.normalize : import numpy as np from sklearn.preprocessing import normalize x = np.random.rand(1000)*10 norm1 = x / np.linalg.norm(x) norm2 = normalize(x[:,np