transformation

Prepare data for MultilayerPerceptronClassifier in scala

房东的猫 提交于 2019-12-01 06:20:48
问题 Please keep in mind I'm new to scala. This is the example I am trying to follow: https://spark.apache.org/docs/1.5.1/ml-ann.html It uses this dataset: https://github.com/apache/spark/blob/master/data/mllib/sample_multiclass_classification_data.txt I have prepared my .csv using the code below to get a data frame for classification in Scala. //imports for ML import org.apache.spark.ml.classification.MultilayerPerceptronClassifier import org.apache.spark.ml.evaluation

Java to Json validation using GSON

℡╲_俬逩灬. 提交于 2019-12-01 00:13:10
While converting Java object to Json string using GSON API, I also want to fail this Json conversion if any of the annotated attribute is null. For example public class Order{ @SerializedName("orderId") @Expose @Required private Integer id; //getter & setter available for id } Now as I am doing Order order = new Order(); JSONObject jsonobj = new JSONObject(gson.toJson(order)); I want to fail the above Java to Json transformation if any of the @Required attribute is null Is this possible using GSON? I wanted to fail Java to Json conversion, if any of the Java attribute is null which is

Missing half of first pixel column after a Graphics Transform Scale

南笙酒味 提交于 2019-11-30 20:15:39
I have noticed that the half of the first pixel column of the image is not drawn after a Graphics Transform Scale on the OnPaint event. All the code needed to reproduce it is at the end of the post. Basically I've created a Class derived from PictureBox called PictureBox2 and it overrides the OnPaint method to perform the Scale transformation. It also changes the InterpolationMode to NearestNeighbor to prevent Graphics from changing the pixels look. The PictureBox control was added to a Form called Form6_GraphicsTest. The control is anchored in all sides. The PictureBox2 back color was changed

SpriteKit missing linear transformation matrices

廉价感情. 提交于 2019-11-30 19:14:36
问题 Does anyone know how to transform ( rotate , scale , skew ) SpriteKit nodes using transformation matrices. couldn't find any support for this in the Spritekit API. 回答1: As mentioned by Fogmeister, you can use an SKEffectNode with a CIFilter. The following works on iOS: // Label let label = SKLabelNode(text: "Hello world") // Transform let transform = CGAffineTransformMake(1, 0.5, 0, 1, 0, 0) // CIFilter let transformFilter = CIFilter(name: "CIAffineTransform")! let val = NSValue

From TimeDelta to float days in Pandas

北城余情 提交于 2019-11-30 18:49:52
I have a TimeDelta column with values that look like this: 2 days 21:54:00.000000000 I would like to have a float representing the number of days, let's say here 2+21/24 = 2.875, neglecting the minutes. Is there a simple way to do this ? I saw an answer suggesting res['Ecart_lacher_collecte'].apply(lambda x: float(x.item().days+x.item().hours/24.)) But I get "AttributeError: 'str' object has no attribute 'item' " Numpy version is '1.10.4' Pandas version is u'0.17.1' The columns has originally been obtained with: lac['DateHeureLacher'] = pd.to_datetime(lac['Date lacher']+' '+lac['Heure lacher']

How can I convert a date in Epoch to “Y-m-d H:i:s” in Javascript?

邮差的信 提交于 2019-11-30 17:35:13
How can I convert following date in epoch: 1293683278 to following readable date: 2010-06-23 09:57:58 using Javascript? Thanks! deadrunk var timestamp = 1293683278; var date = new Date(timestamp * 1000); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); console.log(year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds); See js Date docs for further details Another way: var timestamp = 1293683278; var date = new Date(timestamp * 1000); var

Shear Matrix as a combination of basic transformation?

老子叫甜甜 提交于 2019-11-30 14:54:09
I know the transformation matrices for rotation, scaling, translation etc. I also know the matrix for shear transformation. Now, I need to have the shear matrix-- [1 Sx 0] [0 1 0] [0 0 1] in the form of a combination of other aforesaid transformations . Tried searching, tried brainstorming, but unable to strike! Thanks! Kunal S. Kushwah The x-shear operation for a shearing angle theta reduces to rotations and scaling as follows: (a) Rotate by theta/2 counter-clockwise. (b) Scale with x-scaling factor = sin(theta/2) and y-scaling factor = cos(theta/2) . (c) Rotate by 45 degree clockwise. (d)

Find and replace entire HTML nodes with Nokogiri

巧了我就是萌 提交于 2019-11-30 12:37:37
i have an HTML, that should be transformed, having some tags replaced with another tags. I don't know about these tags, because they will come from db. So, set_attribute or name methods of Nokogiri are not suitable for me. I need to do it, in a way, like in this pseudo-code: def preprocess_content doc = Nokogiri::HTML( self.content ) doc.css("div.to-replace").each do |div| # "get_html_text" will obtain HTML from db. It can be anything, even another tags, tag groups etc. div.replace self.get_html_text end self.content = doc.css("body").first.inner_html end I found Nokogiri::XML::Node::replace

How can you produce sharp paint results when rotating a BufferedImage?

不打扰是莪最后的温柔 提交于 2019-11-30 01:38:35
One attempted approach was to use TexturePaint and g.fillRect() to paint the image. This however requires you to create a new TexturePaint and Rectangle2D object each time you paint an image, which isn't ideal - and doesn't help anyway. When I use g.drawImage(BufferedImage,...) , the rotated images appear to be blurred/soft. I'm familiar with RenderingHints and double-buffering (which is what I'm doing, I think), I just find it difficult to believe that you can't easily and efficiently rotate an image in Java that produces sharp results. Code for using TexturePaint looks something like this.

bounding box of numpy array

时光怂恿深爱的人放手 提交于 2019-11-30 00:07:24
Suppose you have a 2D numpy array with some random values and surrounding zeros. Example "tilted rectangle": import numpy as np from skimage import transform img1 = np.zeros((100,100)) img1[25:75,25:75] = 1. img2 = transform.rotate(img1, 45) Now I want to find the smallest bounding rectangle for all the nonzero data. For example: a = np.where(img2 != 0) bbox = img2[np.min(a[0]):np.max(a[0])+1, np.min(a[1]):np.max(a[1])+1] What would be the fastest way to achieve this result? I am sure there is a better way since the np.where function takes quite a time if I am e.g. using 1000x1000 data sets.