New to Numpy and Arrays, my mind is getting bent like warm metal over coals not able to understand how this should work.
I got this homework question that I've been stuck on for days and I have tried understanding it but the better of me I just cant grasp the concept.
The Question
A 3 by 4 by 4 is created with “arr = np.linspace(1, 48, 48).reshape(3, 4,
4)”. Index or slice this array to obtain the following:
■ 20.0
■ [ 9. 10. 11. 12.]
■ [[33. 34. 35. 36.] [37. 38. 39. 40.] [41. 42. 43. 44.] [45. 46. 47. 48.]]
■ [[5. 6.], [21. 22.] [37. 38.]]
■ [[36. 35.] [40. 39.] [44. 43.] [48. 47.]]
■ [[13. 9. 5. 1.] [29. 25. 21. 17.] [45. 41. 37. 33.]]
■ [[1. 4.] [45. 48.]]
■ [[25. 26. 27. 28.], [29. 30. 31. 32.], [33. 34. 35. 36.], [37. 38. 39. 40.]]
Hint: use flatten and reshape.
The documentation they gave us with this question is limited and as a newbie to this is not making sense at all...
Any help would be appreciated.
Thanks in advance Faz
EDIT*
So I kinda get the concept
print("Array range printed for [9. 10. 11. 12.]\n")
print(arr[0:1, 2])
print(
"\nArray range printed for 20")
print(arr[1, 0, -1])
print(
"\nArray range printed for [[33. 34. 35. 36.] [37. 38. 39. 40.] [41. 42. 43. 44.] [45. 46. 47. 48.]]\n")
print(arr[2])
But I am sitting with this one at the moment
print(
"\nArray range printed for [[5. 6.], [21. 22.] [37. 38.]]\n")
How does one print ONLY two digits with a range of 3?
My current solution gives two values but not the 3 ranges
print(arr[0:2, 1, 1])
Output = [ 6. 22.]
numpy, preferablyipython. Createarras specified.print(arr)to set it. Then practice doing different kinds of indexing, presumably using information that you've been taught.