array

Swift filter array using NSPredicate

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an application written in Swift that is pulling in the users contacts from their address book. I want to filter out the contact that only contain a company name (so that you get your "assumed" real person contact and not businesses) Here is how this is being accomplish in the Objective-C version of my app: NSArray *allContacts = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id person, NSDictionary *bindings) { NSString *firstName =

Replace subarrays in numpy

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given an array, >>> n = 2 >>> a = numpy.array([[[1,1,1],[1,2,3],[1,3,4]]]*n) >>> a array([[[1, 1, 1], [1, 2, 3], [1, 3, 4]], [[1, 1, 1], [1, 2, 3], [1, 3, 4]]]) I know that it's possible to replace values in it succinctly like so, >>> a[a==2] = 0 >>> a array([[[1, 1, 1], [1, 0, 3], [1, 3, 4]], [[1, 1, 1], [1, 0, 3], [1, 3, 4]]]) Is it possible to do the same for an entire row (last axis) in the array? I know that a[a==[1,2,3]] = 11 will work and replace all the elements of the matching subarrays with 11, but I'd like to substitute a

PHP - $_FILES array is empty [duplicate]

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Why would $_FILES be empty when uploading files to PHP? 20 answers Yes, the enctype attribute is set. Other forms/form-hanlders work fine so the temp directory must be writable. I'm out of Ideas. I checked the post values and $_POST['file'] exists and contains the name of the file. Here is my form and the PHP that handles it. What am I missing? <form action='orl_ftp.php' method='post' enctype='multipart/form-data'> <table> <tr> <td>Choose File: </td> <td><INPUT type='file' id='file' name='file'></td>

Type is not supported for deserialization of an array

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to dezerialize an array but I keep running into an error. JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); Profiles thingy = jsonSerializer.Deserialize<Profiles>(fileContents); This is the code that gives me the error: Type is not supported for deserialization of an array. This is how my JSON looks: [ { "Number": 123, "Name": "ABC", "ID": 123, "Address": "ABC" } ] 回答1: You just need to deserialize it to a collection of some sort - e.g. an array. After all, your JSON does represent an array, not a single item.

Explicitly select items from a Python list or tuple

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have the following Python list (can also be a tuple): myList = [ 'foo' , 'bar' , 'baz' , 'quux' ] I can say >>> myList [ 0 : 3 ] [ 'foo' , 'bar' , 'baz' ] >>> myList [:: 2 ] [ 'foo' , 'baz' ] >>> myList [ 1 :: 2 ] [ 'bar' , 'quux' ] How do I explicitly pick out items whose indices have no specific patterns? For example, I want to select [0,2,3] . Or from a very big list of 1000 items, I want to select [87, 342, 217, 998, 500] . Is there some Python syntax that does that? Something that looks like: >>> myBigList [ 87 , 342 , 217 ,

Numpy: Replace every value in the array with the mean of its adjacent elements

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an ndarray, and I want to replace every value in the array with the mean of its adjacent elements. The code below can do the job, but it is super slow when I have 700 arrays all with shape (7000, 7000) , so I wonder if there are better ways to do it. Thanks! a = np.array(([1,2,3,4,5,6,7,8,9],[4,5,6,7,8,9,10,11,12],[3,4,5,6,7,8,9,10,11])) row,col = a.shape new_arr = np.ndarray(a.shape) for x in xrange(row): for y in xrange(col): min_x = max(0, x-1) min_y = max(0, y-1) new_arr[x][y] = a[min_x:(x+2),min_y:(y+2)].mean() print new_arr 回答1:

How to create an image pixel by pixel

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to create an UIImage pixel by pixel in swift 3 I have searched but couldn't find the code that actually works So let me explain, I have an array with characters var array = ["w", "x", "y", "x", "y", "y", "y", "x", "x", "x", "w", "x", "y", "w", "y"] //there will be like 26 millions of those if it's w, the color of the pixel will be blue if it's x, the color of the pixel will be red if it's y, the color of the pixel will be green if it's v, the color of the pixel will be black I want to create an image from those characters and store it

Typescript difference between two arrays

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to return the missing values of list_a from list_b in TypeScrpit? For example: var a1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; var a2 = ['a', 'b', 'c', 'd', 'z']; The result value is ['e', 'f', 'g']. thanks in advance 回答1: There are probably a lot of ways, for example using the Array.prototype.filter() : var a1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; var a2 = ['a', 'b', 'c', 'd']; let missing = a1.filter(item => a2.indexOf(item) < 0); console.log(missing); // ["e", "f", "g"] ( code in playground ) Edit The filter function runs

Notice: Undefined offset: 0 in

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am getting this PHP error, what does it mean? Notice: Undefined offset: 0 in C:\xampp\htdocs\mywebsite\reddit_vote_tut\src\votes.php on line 41 From this code: 回答1: You are asking for the value at key 0 of $votes . It is an array that does not contain that key. The array $votes is not set, so when PHP is trying to access the key 0 of the array, it encounters an undefined offset for [0] and [1] and throws the error. If you have an array: $new_array = array('1','2','3'); We can now access: $new_array[0]; $new_array[1]; $new_array[2]; If we

Producing 2D array from a 1D array in MATLAB

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Does anyone know if there is a way to produce a 2D array from a 1D array, where the rows in the 2D are generated by repeating the corresponding elements in the 1D array. I.e.: 1D array 2D array | 1 | | 1 1 1 1 1 | | 2 | | 2 2 2 2 2 | | 3 | -> | 3 3 3 3 3 | | 4 | | 4 4 4 4 4 | | 5 | | 5 5 5 5 5 | 回答1: In the spirit of bonus answers, here are some of my own: Let A = (1:5)' Using indices [faster than repmat]: B = A (:, ones ( 5 , 1 )) Using matrix outer product: B = A * ones ( 1 , 5 ) Using bsxfun() [not the best way of doing it] B =