Error: array index out of range in multidimensional array
As the commentators @C_X & @MartinR say, your array is empty. Here's how to initialise it as you want...
var tile = [[Int]](count:4, repeatedValue: [Int](count: 4, repeatedValue: 0))
for index in 0 ..< 4 {
for sindex in 0 ..< 4 {
tile[index][sindex] = 0 // no error here now...
print("\(index) \(sindex)")
}
}
...of course, the for
loops are now redundant, if you just want zeroes!
Index out of range for multi dimensional array
for (int i = 0; i < posAr_ItemManager.GetLength(0); i++)
{
for (int j = 0; j < posAr_ItemManager.GetLength(1); j++)
{
for (int z = 0; z < posAr_ItemManager.GetLength(2); z++)
look very carefully at the middle tests. Also, consider hoisting the GetLength
tests so you only do them once per dimension. Perhaps:
int rows = posAr_ItemManager.GetLength(0), columns = posAr_ItemManager.GetLength(1),
categories = posAr_ItemManager.GetLength(2);
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < columns; col++)
{
for (int cat = 0; cat < categories; cat++)
Python multidimensional array list index out of range
In case you just want to remove some elements from the list you could iterate it from end to beginning which would allow you to remove items without causing IndexError
:
list2 = [["John Doe","1"],["Jane Smith","0"],["Firstname Lastname","1"]]
for i in range(len(list2) - 1, -1, -1):
list2[i][1] = int(list2[i][1])
if int(list2[i][1]) == 1:
list2.pop(i)
print(list2)
Output:
[['Jane Smith', 0]]
Of course you could just use list comprehension to create a new list:
list2 = [[x[0], int(x[1])] for x in list2 if int(x[1]) != 1]
Related Topics
Rotation Only in One Viewcontroller
How to Only Disable Scroll in Scrollview But Not Content View
Is There a Simple Way to Edit/Modify a Uilocalnotification
iOS - Is Motion Activity Enabled in Settings > Privacy > Motion Activity
Determinate Finish Loading Website in Webview with Swift in Xcode
Nsurlsessiondatatask Datataskwithurl Completion Handler Not Getting Called
Replace a Particular Color Inside an Image with Another Color
Swift iOS9 New Contacts Framework - How to Retrieve Only Cncontact That Has a Valid Email Address
Get Error Code -11843 While Exporting Mp3 File in Ipod Library Since iOS 5.1
How to Detect iOS 6 and All Minor Versions by User Agent
How to Share Nsdata or Phasset Video Using Facebook iOS Sdk 4.0 Fbsdksharedialog
How to Display the Emoji and Special Characters in Uilabel and Uitextviews
How to Save Created PDF in Document Folder and Merge in iOS
How to Handle "Cfnetwork Sslhandshake Failed" in iOS
Custom Back Indicator Image and iOS 11
Xcode Error While Validation - "Your Binary Is Not Optimized for iPhone 5"