%use numpy(0.1.4) val a = array(arrayOf(1L, 2L, 3L)) val b = array(listOf(listOf(1.5f, 2f, 3f), listOf(4f, 5f, 6f))) val c = array( listOf( listOf(listOf(1.5f, 2f, 3f), listOf(4f, 5f, 6f)), listOf(listOf(3f, 2f, 1f), listOf(4f, 5f, 6f)) ) ) zeros(3, 4) // Create an array of zeros ones(2, 3, 4) // Create an array of ones val d = arange(10, 25, 5) // Create an array of evenly spaced values (step value) linspace(0, 2, 9) // Create an array of evenly spaced values (number of samples) val e = full(intArrayOf(2, 2), 7L) // Create a constant array val f = eye(2) // Create a 2x2 identity matrix Random.random(2, 2) // Create an array with random values empty(3, 2) // Create an empty array // a.toFile("my_array") // fromfile("my_array") a.shape // Array domensions b.ndim // Number of array dimensions e.size // Number of array elements b.dtype // Dara type of array elements b.dtype.name // Name of data type b.asType() // Convert an array to a different type val g = a - b println("Subtraction:") println(a - b) // Subraction println("Addition:") println(b + a) // Addition println("Division:") println(a / b) // Division println("Multiplication:") println(a * b) // Multiplication exp(b) // Exponentiation sqrt(b) // Square root sin(a) // Sin cos(b) // Cos log(a) // natural logarithm e.dot(f) // Dot product println("Element-wise comparison") println(c eq b) println("Element-wise comparison") println(a lt 2) println("Array comparison") println(a == b) a.sum() // Array sum a.min() // Array minimum value b.max(0) // Maximum value of an array row b.cumSum(1) // Cumulative sum of the lements a.mean() // Mean median(b) // Median corrcoef(a) // Correlation coefficient std(d) // Standard deviation var h = a.view() copy(a) h = copy(a) a.sort() c.sort(axis = 0) println(a[2]) // Select the element at the 2nd index println(b[1, 2]) // Select the element at row 1 column 2 println(a[0..2]) // Select items at index 0 and 1 println(b[0..2, 1]) // Select items at rows 0 and 1 in column 1 println(b[None..1]) // Select all items at row 0 println(c[1, None..None, None..None]) // Same as [1, ...] or [1, :, :] in Python println(a[None..None..-1]) // Reversed array a a[a lt 2] // Select elements from a less than 2 println(b[arrayOf(1, 0, 1, 0), arrayOf(0, 1, 2, 0)]) // Select elements (1,0), (0,1), (1,2) and (0, 0) println(b[arrayOf(1, 0, 1, 0)][None..None, arrayOf(0, 1, 2, 0)]) // Select a subset of the matrix's rows and columns // Flat array iteration for (element in a.flatIter()) { print("$element ") } println() // Iteration along the axes of the array for (ax in b) { println(ax) } val i = transpose(b) // Permute array dimensions i.t b.ravel() // Flatten the array g.reshape(3, -2) // Reshape, but don't chenge data h.resize(2, 6) // Change to new array with shape (2,6) append(h.view(), g) // Append items to an array insert(a, 1, array(arrayOf(5L))) // Insert items in an array delete(a, 1) // Delete items from an array println(concatenate(a, d, axis = 0)) // Concatenate arrays println(vstack(a.view(), b)) // Stack arrays vertically println(hstack(e.view(), f)) // Stack arrays horizontally println(columnStack(a, d)) // Create stacked column-wise arrays hsplit(a, 3) // Split the array horizontally at the 3rd index