convert

python csv reader - convert string to int on the for line when iterating

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm interested in not having to write map the int function to the tuple of strings where I currently have it. See the last part of my example: import os import csv filepath = os.path.normpath("c:/temp/test.csv") individualFile = open(filepath,'rb') dialect = csv.Sniffer().sniff(individualFile.read(1000)) individualFile.seek(0) reader = csv.reader(individualFile,dialect) names = reader.next() print names def buildTree(arityList): if arityList == []: return 0 else: tree = {} for i in xrange(arityList[0][0],arityList[0][1]+1): tree[i] =

Convert unicode with utf-8 string as content to str

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using pyquery to parse a page: dom = PyQuery('http://zh.wikipedia.org/w/index.php', {'title': 'CSS', 'printable': 'yes', 'variant': 'zh-cn'}) content = dom('#mw-content-text > p').eq(0).text() but what I get in content is a unicode string with utf-8 encoded content: u'\xe5\xb1\x82\xe5\x8f\xa0\xe6\xa0\xb7\xe5\xbc\x8f\xe8\xa1\xa8...' how could I convert it to str without lost the content? to make it clear: I want conent == '\xe5\xb1\x82\xe5\x8f\xa0\xe6\xa0\xb7\xe5\xbc\x8f\xe8\xa1\xa8' not conent == u'\xe5\xb1\x82\xe5\x8f\xa0\xe6\xa0\xb7

How to convert date format in vb.net?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am getting xml response date format string is "MM/dd/yyyy h:mm:ss a" but I need convert other date format ""dd MMM yy HH:mm"". How to convert date format in vb.net? Please give me any suggestion. 回答1: Assuming you want to convert the xml string value to a proper DateTime variable, Net has many methods for this: ' a date value in the string format specified: Dim xmlDate As String = "07/15/2014 7:07:33 AM" ' create a DATE variable from that string in a known format: Dim newDate As Date = DateTime.ParseExact(xmlDate, "MM/dd/yyyy h:mm:ss tt",

PostGIS - convert multipolygon to single polygon

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is it possible to import a shape file containing multipolygons into single polygon in PostGIS? Whenever I try importing a shape file of a polygon, it is stored as a multipolygon (as opposed to a single polygon) in a geom column. Thus, I am unable to extract it as a single polygon value from the multipolygon. All helpful suggestions much appreciated 回答1: You can use ST_GeometryN together with ST_NumGeometries and the generate_series function to obtain what you need. Let's assume you have the table from Jakub's example: CREATE TABLE multi AS(

Convert Android camera2 api YUV_420_888 to RGB

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am writing an app that takes the camera feed, converts it to rgb, in order to do some processing. It works fine on the old camera implementation which uses NV21 Yuv format. The issue I am having is with the new Yuv format, YUV_420_888. The image is no longer converted correctly to RGB in the new Camera2 Api which sends YUV_420_888 yuv format instead of NV21 (YUV_420_SP) format. Can someone please tell me how should I convert YUV_420_888 to RGB? Thanks 回答1: In my approach I use OpenCV Mat and script from https://gist.github.com

How to convert v8 Value to Array

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm writing a c++ extension to v8, and want to pass an Array object into it. I see the incoming argument can be tested by IsArray(), but there isn't a ToArray(). How do you get access to its Length, and request elements by numeric index? Handle < Value > MyExtension ( const Arguments & args ) { Handle < Value > v = args [ 0 ]; if ( v -> IsArray ()) { // convert to array, find its length, and access its members by index... ? } ... } Must be missing something obvious here. Object can return all its properties, but that's not quite

Convert Keras model to TensorFlow protobuf

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: We're currently training various neural networks using Keras, which is ideal because it has a nice interface and is relatively easy to use, but we'd like to be able to apply them in our production environment. Unfortunately the production environment is C++, so our plan is to: Use the TensorFlow backend to save the model to a protobuf Link our production code to TensorFlow, and then load in the protobuf Unfortunately I don't know how to access the TensorFlow saving utilities from Keras, which normally saves to HDF5 and JSON. How do I save to

Convert.ChangeType How to convert from String to Enum

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: public static T Convert<T>(String value) { return (T)Convert.ChangeType(value, typeof(T)); } public enum Category { Empty, Name, City, Country } Category cat=Convert<Category>("1");//Name=1 When I call Convert.ChangeType , the system throws an exception on the impossibility of conversion from String to Category. How to do the conversion? Maybe I need to implement any converter for my type? 回答1: Use Enum.Parse method for this. public static T Convert<T>(String value) { if (typeof(T).IsEnum) return (T)Enum.Parse(typeof(T), value); return (T

Pandas convert a column of list to dummies

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a dataframe where one column is a list of groups each of my users belongs to. Something like: index groups 0 [ 'a' , 'b' , 'c' ] 1 [ 'c' ] 2 [ 'b' , 'c' , 'e' ] 3 [ 'a' , 'c' ] 4 [ 'b' , 'e' ] And what I would like to do is create a series of dummy columns to identify which groups each user belongs to in order to run some analyses index a b c d e 0 1 1 1 0 0 1 0 0 1 0 0 2 0 1 1 0 1 3 1 0 1 0 0 4 0 1 0 0 0 pd . get_dummies ( df [ 'groups' ]) won't work because that just returns a column for each different list in my column.

Convert NSInteger to NSUInteger?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to convert a NSInteger to a NSUInteger and I googled it and found no real answer. How would I do this? 回答1: NSInteger and NSUInteger are just typedefs for primitive integer types: #if __LP64__ || NS_BUILD_32_LIKE_64 typedef long NSInteger ; typedef unsigned long NSUInteger ; #else typedef int NSInteger ; typedef unsigned int NSUInteger ; #endif As such, you don't need to "convert" between them. A simple cast should be sufficient. Like: NSInteger myInt = 0 ; NSUInteger unsignedInt = ( NSUInteger ) myInt ; 回答2: Since this