0

I have a 2-d numpy array that I convert into a 3-d array by using:

trainSet = numpy.reshape(trainSet, (trainSet.shape[0], 1, trainSet.shape[1]))

My problem is I'm trying to adjust values in the 1st axis (the new one). However, no matter what I try I can not actually figure out how to access the 1's in the new axis. I've tried a multitude of print statements such as

print(trainSet[0][0][0])
print(trainSet[1][0][1])

but no matter what I try I can not print out any 1's, just the contents of the 2-d array. I know it's a 3d array because when I use

print(trainSet.shape)

I get

(12, 1, 793)

Any help would be immensely appreciated!

1
  • 1
    You index a 3d array with expressions like M[i, j, k], M[:, 0, :], etc Commented Mar 8, 2017 at 23:40

3 Answers 3

1

The one refers to the size of that particular dimension, not the content of the array. The array [[5 5]] has shape (1, 2) but, still, you don't really expect its values must include 1 for that reason, do you?

What inserting a dimension of length one does is increasing the nesting level by one, so a 2d array [[a b] [c d]] will become [[[a b] [c d]]] or [[[a b]] [[c d]]] or [[[a] [b]] [[c] [d]]] depending on where you insert the new axis.

In particular, there are no new elements.

Sign up to request clarification or add additional context in comments.

Comments

0

If I didn't mistake your question, what you want is

trainSet[:,0,:]

Comments

0

the amount of values remains the same, you're just creating a 3D structure instead of the 2D structure.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.