Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?

Scala 2.7 tried to add functionality to Java [] arrays, and ran into corner cases that were problematic. Scala 2.8 has declared that Array[T] is T[], but it provides wrappers and equivalents. Try the following in 2.8 (edit/note: as of RC3, GenericArray is ArraySeq–thanks to retronym for pointing this out): import scala.collection.mutable.{GenericArray=>GArray, WrappedArray=>WArray} scala> GArray(0,1,2) … Read more

Is there a convenient way to apply a lookup table to a large array in numpy?

You can just use image to index into lut if lut is 1D. Here’s a starter on indexing in NumPy: http://www.scipy.org/Tentative_NumPy_Tutorial#head-864862d3f2bb4c32f04260fac61eb4ef34788c4c In [54]: lut = np.arange(10) * 10 In [55]: img = np.random.randint(0,9,size=(3,3)) In [56]: lut Out[56]: array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90]) In [57]: img Out[57]: array([[2, 2, 4], … Read more

Swift 4 JSON Codable – value returned is sometimes an object, others an array

You might encapsulate the ambiguity of the result using an Enum with Associated Values (String and Array in this case), for example: enum MetadataType: Codable { case array([String]) case string(String) init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() do { self = try .array(container.decode(Array.self)) } catch DecodingError.typeMismatch { do { self = try … Read more