array

How to repair warning: missing braces around initializer?

匿名 (未验证) 提交于 2019-12-03 01:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The warning is produced by the c code generated by vala. warning: missing braces around initializer The code works but the warning is annoying. The vala code referenced by the warning is struct Position {uint x; uint y;} private static Position positions[8]; The generated C code is static Position det_positions[8] = {0}; I've tried initializing positions half a dozen different ways but can't seem to get the syntax to satisfy the warning. Is this GCC bug 53119 or is there a way to fix it? 回答1: Yes, this appears to be related to GCC bug 53119

NSArray + remove item from array

匿名 (未验证) 提交于 2019-12-03 01:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to remove an item from NSArray. 回答1: NSArray is not mutable, that is, you cannot modify it. You should take a look at NSMutableArray . Check out the "Removing Objects" section, you'll find there many functions that allow you to remove items: [anArray removeObjectAtIndex: index]; [anArray removeObject: item]; [anArray removeLastObject]; 回答2: NSMutableArray *arrayThatYouCanRemoveObjects = [NSMutableArray arrayWithArray:your_array]; [arrayThatYouCanRemoveObjects removeObjectAtIndex:your_object_index]; [your_array release]; your_array = [

Get year, month or day from numpy datetime64

匿名 (未验证) 提交于 2019-12-03 01:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an array of datetime64 type: dates = np.datetime64(['2010-10-17', '2011-05-13', "2012-01-15"]) Is there a better way than looping through each element just to get np.array of years: years = f(dates) #output: array([2010, 2011, 2012], dtype=int8) #or dtype = string I'm using stable numpy version 1.6.2. 回答1: As datetime is not stable in numpy I would use pandas for this: In [52]: import pandas as pd In [53]: dates = pd.DatetimeIndex(['2010-10-17', '2011-05-13', "2012-01-15"]) In [54]: dates.year Out[54]: array([2010, 2011, 2012], dtype

Get year, month or day from numpy datetime64

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an array of datetime64 type: dates = np.datetime64(['2010-10-17', '2011-05-13', "2012-01-15"]) Is there a better way than looping through each element just to get np.array of years: years = f(dates) #output: array([2010, 2011, 2012], dtype=int8) #or dtype = string I'm using stable numpy version 1.6.2. 回答1: As datetime is not stable in numpy I would use pandas for this: In [52]: import pandas as pd In [53]: dates = pd.DatetimeIndex(['2010-10-17', '2011-05-13', "2012-01-15"]) In [54]: dates.year Out[54]: array([2010, 2011, 2012], dtype

Fastest pairwise distance metric in python

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an 1D array of numbers, and want to calculate all pairwise euclidean distances. I have a method (thanks to SO) of doing this with broadcasting, but it's inefficient because it calculates each distance twice. And it doesn't scale well. Here's an example that gives me what I want with an array of 1000 numbers. import numpy as np import random r = np.array([random.randrange(1, 1000) for _ in range(0, 1000)]) dists = np.abs(r - r[:, None]) What's the fastest implementation in scipy/numpy/scikit-learn that I can use to do this, given that

usort(): Array was modified by the user comparison function

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a web application that runs fine on our Linux servers but when running on Mac OS with the Zend Community Edition Server using PHP 5.3 we get the error: usort(): Array was modified by the user comparison function every time a page loads for the first time (it takes about 2 minutes for a page to tick over and load, on the linux servers the page loads in 1 second). Has anyone else experienced this or has any idea how I can fix the problem, I have tried playing around with PHP and Apache memory settings with no luck. 回答1: There is a PHP

How to cast array elements to strings in PHP?

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If I have a array with objects: $a = array($objA, $objB); (each object has a __toString() -method) How can I cast all array elements to string so that array $a contains no more objects but their string representation? Is there a one-liner or do I have to manually loop through the array? 回答1: A one-liner: $a = array_map('strval', $a); // strval is a callback function See PHP DOCS: array_map strval Enjoy! ;) 回答2: Are you looking for implode ? $array = array('lastname', 'email', 'phone'); $comma_separated = implode(",", $array); echo $comma

Java unchecked: unchecked generic array creation for varargs parameter

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have set Netbeans to show unchecked warnings in my Java code, but I am failing to understand the error on the following lines: private List cocNumbers; private List vatNumbers; private List ibans; private List banks; ... List > combinations = Utils.createCombinations(cocNumbers, vatNumbers, ibans); Gives: [unchecked] unchecked generic array creation for varargs parameter of type List [] Method source: /** * Returns a list of all possible combinations of the entered array of lists. * * Example: [["A", "B"], ["0", "1", "2"]] * Returns: [["A"

How to output list of floats to a binary file in Python

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a list of floating-point values in Python: floats = [3.14, 2.7, 0.0, -1.0, 1.1] I would like to write these values out to a binary file using IEEE 32-bit encoding. What is the best way to do this in Python? My list actually contains about 200 MB of data, so something "not too slow" would be best. Since there are 5 values, I just want a 20-byte file as output. 回答1: Alex is absolutely right, it's more efficient to do it this way: from array import array output_file = open('file', 'wb') float_array = array('d', [3.14, 2.7, 0.0, -1.0, 1.1

Accessing array values using array key from Twig

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Does anyone know how (of if it's even possible!) to do this in Twig? I can't see anything in the documentation as to whether it's possible. The PHP array is structured as below: $data [ 'data' ][ 'a' ][ 'title' ] = 'Title 1' ; $data [ 'data' ][ 'a' ][ 'title' ] = 'Title 2' ; $data [ 'data' ][ 'b' ][ 'title' ] = 'Title 3' ; Twig template code below: {% for letter in 'a' .. 'z' %} {{ letter }} {% for key , item1 in data %} {% for item2 in item1 %} {{ item2 [ key ]. title }} {% endfor %} {% endfor %} {% endfor %} Edit: After further