# How do I troubleshoot when I get a Part::partd or a Part::partw error?

Mathematica has produced the following error message:

Part::partd: Part specification ... is longer than depth of object?

What is partd?

I think I may have flattened or (unflattened) arrays and am not sure how to locate the exact object?

-
Probably means that you are trying to access an array with more dimensions than it has (e.g. myArray[[i,j]] when myArray is a single dimension). –  Guillochon Jan 16 '13 at 0:42

Two of the most common error messages that users encounter when working with parts of lists are Part::partd and Part::partw (look up Message for the error message syntax). Both of these are because the user is trying to access an invalid part of the expression (the "object" referred to in the error message), but there's a subtle difference between the two:

### Part::partw

This error occurs when you're trying to obtain a part of an expression at a position longer than the Length of the expression (or subexpression). For example:

exprw = {{a, b}, {c, d, e}};
exprw[[2, 3]]
(* e *)

exprw[[1, 3]]


Part::partw: "Part 3 of {a,b} does not exist"

You can see that we tried to access the third element of a two element list and this results in an error. In general, if you get a partw error, look at the size of your index and check if it makes sense to your application. If not, you've found the source of your error. If it does, then your application/model is most likely faulty and you might want to check that instead.

### Part::partd

This error occurs when you're trying to index the expression at a depth deeper than the maximum depth of the expression. In general, you can index the elements of an expression at Level $n$ by using exactly $n$ indices and you can index any element in an expression of Depth $d$ with most $d-1$ indices. However, when you try to index an expression at a depth greater than its maximum depth or you try to access an element at level $n$ with more than $n$ indices (which again translates to deeper depth), you get a partd error. For example, consider:

exprd = {{a, b}, {c, d, {e}}};


The maximum depth or Depth[exprd] is 4. Now try indexing with 4 indices:

exprd[[1, 1, 1, 1]]


Part::partd: "Part specification {{a,b},{c,d,{e}}}[[1,1,1,1]] is longer than depth of object"

So if you get a partd error, check to see if you're using the right number of indices for the given expression.

-
Thanks this explains it quite well. –  sebastian c. Jan 16 '13 at 10:04