How to slice an array in Bash

Looking the “Array” section in the bash(1) man page, I didn’t find a way to slice an array. So I came up with this overly complicated function: #!/bin/bash # @brief: slice a bash array # @arg1: output-name # @arg2: input-name # @args: seq args # ———————————————- function slice() { local output=$1 local input=$2 shift 2 … Read more

Explanation of [].slice.call in javascript?

I stumbled onto this neat shortcut for converting a DOM NodeList into a regular array, but I must admit, I don’t completely understand how it works: [].slice.call(document.querySelectorAll(‘a’), 0) So it starts with an empty array [], then slice is used to convert the result of call to a new array yeah? The bit I don’t … Read more

Select rows in pandas MultiIndex DataFrame

What are the most common pandas ways to select/filter rows of a dataframe whose index is a MultiIndex? Slicing based on a single value/label Slicing based on multiple labels from one or more levels Filtering on boolean conditions and expressions Which methods are applicable in what circumstances Assumptions for simplicity: input dataframe does not have … Read more

ValueError: setting an array element with a sequence

This Python code: import numpy as p def firstfunction(): UnFilteredDuringExSummaryOfMeansArray = [] MeanOutputHeader=[‘TestID’,’ConditionName’,’FilterType’,’RRMean’,’HRMean’, ‘dZdtMaxVoltageMean’,’BZMean’,’ZXMean’,’LVETMean’,’Z0Mean’, ‘StrokeVolumeMean’,’CardiacOutputMean’,’VelocityIndexMean’] dataMatrix = BeatByBeatMatrixOfMatrices[column] roughTrimmedMatrix = p.array(dataMatrix[1:,1:17]) trimmedMatrix = p.array(roughTrimmedMatrix,dtype=p.float64) #ERROR THROWN HERE myMeans = p.mean(trimmedMatrix,axis=0,dtype=p.float64) conditionMeansArray = [TestID,testCondition,’UnfilteredBefore’,myMeans[3], myMeans[4], myMeans[6], myMeans[9], myMeans[10], myMeans[11], myMeans[12], myMeans[13], myMeans[14], myMeans[15]] UnFilteredDuringExSummaryOfMeansArray.append(conditionMeansArray) secondfunction(UnFilteredDuringExSummaryOfMeansArray) return def secondfunction(UnFilteredDuringExSummaryOfMeansArray): RRDuringArray = p.array(UnFilteredDuringExSummaryOfMeansArray,dtype=p.float64)[1:,3] return firstfunction() Throws this error … Read more

How to take column-slices of dataframe in pandas

I load some machine learning data from a CSV file. The first 2 columns are observations and the remaining columns are features. Currently, I do the following: data = pandas.read_csv(‘mydata.csv’) which gives something like: data = pandas.DataFrame(np.random.rand(10,5), columns = list(‘abcde’)) I’d like to slice this dataframe in two dataframes: one containing the columns a and … Read more