convenience-methods

Simple/Direct/Heredoc way of constructing a HTML string in Java

泄露秘密 提交于 2019-11-28 23:04:39
In python I can construct a HTML string without worrying about escaping special characters like < or " by simply enclosing the string in triple quotes like: html_string = """ <html> <body> <p>My text with "quotes" and whatnot!<p> </body> </html> """ Is there a similar way to do this in Java? It can't be done in Java like in Python. However if you are using Eclipse go to Window->Preferences->Java->Editor->Typing The last check box is "Escape text when pasting into a String literal". Check that. Now when you paste when your cursor is between quotation marks it'll be escaped. No, but some tools

How to normalize a NumPy array to within a certain range?

和自甴很熟 提交于 2019-11-27 02:39:16
After doing some processing on an audio or image array, it needs to be normalized within a range before it can be written back to a file. This can be done like so: # Normalize audio channels to between -1.0 and +1.0 audio[:,0] = audio[:,0]/abs(audio[:,0]).max() audio[:,1] = audio[:,1]/abs(audio[:,1]).max() # Normalize image to between 0 and 255 image = image/(image.max()/255.0) Is there a less verbose, convenience function way to do this? matplotlib.colors.Normalize() doesn't seem to be related. audio /= np.max(np.abs(audio),axis=0) image *= (255.0/image.max()) Using /= and *= allows you to