indices

SwiftUI ForEach with .indices() does not update after onDelete

雨燕双飞 提交于 2020-08-08 05:32:00
问题 my problem is: I have simple array with some Items. I want to display a List with these items using a ForEach with .indices() . (This is because my actual problem handles with Toggle in a List and for the isOn binding I need the index to address a model that is bound to an EnvironmentObject ). So the solution to loop over the array items is no possible solution for my problem. The simplified starting point looks like this: struct ContentView: View { @State var items = ["Item1", "Item2",

Python numpy array sum over certain indices

女生的网名这么多〃 提交于 2020-07-06 10:59:06
问题 How to perform a sum just for a list of indices over numpy array, e.g., if I have an array a = [1,2,3,4] and a list of indices to sum, indices = [0, 2] and I want a fast operation to give me the answer 4 because the value for summing value at index 0 and index 2 in a is 4 回答1: You can use sum directly after indexing with indices : a = np.array([1,2,3,4]) indices = [0, 2] a[indices].sum() 回答2: The accepted a[indices].sum() approach copies data and creates a new array, which might cause problem

Implementing ordering for List of objects in C# and methods for changing the index of the object

丶灬走出姿态 提交于 2020-04-30 08:01:30
问题 Say I have a list of object Person { public string Name {get; set;} public string Gender {get; set;} } What I want is to create a List that I can order by using a property called OrderIndex. So I add this property to the Person object: { public string Name {get; set;} public string Gender {get; set;} public int OrderIndex {get; set;} } The purpose of this OrderIndex property is to place the Person object in the list at a specific index for ranking the Person object higher. But I am very

Implementing ordering for List of objects in C# and methods for changing the index of the object

烂漫一生 提交于 2020-04-30 07:59:32
问题 Say I have a list of object Person { public string Name {get; set;} public string Gender {get; set;} } What I want is to create a List that I can order by using a property called OrderIndex. So I add this property to the Person object: { public string Name {get; set;} public string Gender {get; set;} public int OrderIndex {get; set;} } The purpose of this OrderIndex property is to place the Person object in the list at a specific index for ranking the Person object higher. But I am very

How to modify fields of a nested custom data type with lenses, when modifications depend on indices

人走茶凉 提交于 2020-03-25 21:54:08
问题 Considering the following : {-# LANGUAGE TemplateHaskell #-} import Control.Lens data Typex = Typex { _level :: Int , _coordinate :: (Int, Int) , _connections :: [(Int,(Int,Int))] } deriving Show makeLenses ''Typex initTypexLevel :: Int -> Int -> Int -> [Typex] initTypexLevel a b c = [ Typex a (x, y) [(0,(0,0))] | x <- [0..b], y <- [0..c] ] buildNestedTypexs :: [(Int, Int)] -> [[Typex]] buildNestedTypexs pts = setConnections [ initTypexLevel i y y | (i,(_,y)) <- zip [0..] pts ] setConnections

How to modify fields of a nested custom data type with lenses, when modifications depend on indices

瘦欲@ 提交于 2020-03-25 21:54:08
问题 Considering the following : {-# LANGUAGE TemplateHaskell #-} import Control.Lens data Typex = Typex { _level :: Int , _coordinate :: (Int, Int) , _connections :: [(Int,(Int,Int))] } deriving Show makeLenses ''Typex initTypexLevel :: Int -> Int -> Int -> [Typex] initTypexLevel a b c = [ Typex a (x, y) [(0,(0,0))] | x <- [0..b], y <- [0..c] ] buildNestedTypexs :: [(Int, Int)] -> [[Typex]] buildNestedTypexs pts = setConnections [ initTypexLevel i y y | (i,(_,y)) <- zip [0..] pts ] setConnections

Index mapping between two sorted partially overlapping numpy arrays

烂漫一生 提交于 2020-01-11 13:27:28
问题 I want to solve something like the problem detailed at Find index mapping between two numpy arrays, but where the two arrays do not necessarily contain the same set of values, although their values are unique within each array, and are sorted. E.g. if I have two arrays: a = np.array([1.1, 2.2, 3.3, 4.4, 5.5]) b = np.array([2.2, 3.0, 4.4, 6.0]) I want to get an array of the same length as a which gives the index into b where the matching element is, or -1 if there is no match. I.e. in this