how to use values of a pandas DataFrame as numpy array index

Sounak

I have a pandas dataFrame like this.

enter image description here

The X, Y, Z are they (x,y,z) coordinates that represent a point inside a cube of side-length 255.

I want to create a numpy array/dataFrame from this, whose index will be the (x,y,z) coordinates and value is the intensity.

the output should be

data[133,55,250] = 8
data[133,61,254] = 21
...

I tried something like this

data = np.zeros((255,255,255), dtype=np.int)
index = np.array((temp['X'], temp['Y'], temp['Z']))

but returned index is a (3,15) array.

I want a index where

data[index] = intensity

will give me my result.

I am kind of lost. Some help will be appreciated.

Thanks.

unutbu

Instead of

index = np.array((temp['X'], temp['Y'], temp['Z']))

you could use integer array indexing to perform the assignment:

data = np.zeros((256, 256, 256), dtype=np.int)
data[temp['X'], temp['Y'], temp['Z']] = temp['intensity']

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to use values of a pandas DataFrame as numpy array index

From Dev

What index should I use to convert a numpy array into a pandas dataframe?

From Dev

Use pandas dataframe apply to replace row values from a numpy array

From Dev

Use index values as category values in pandas dataframe

From Dev

How to efficiently iterate a pandas DataFrame and increment a NumPy array on these values?

From Dev

How to add '$' to my pandas dataframe values and use a column as index?

From Dev

Accessing Pandas dataframe values when index values contained in separate numpy array

From Dev

Create Pandas dataframe from numpy array and use first column of the array as index

From Dev

replacing pandas dataframe variable values with a numpy array

From Dev

Modify pandas dataframe values with numpy array

From Dev

numpy array converted to pandas dataframe drops values

From Dev

How to exchange the role of values and index in pandas DataFrame?

From Dev

How to set index values in a MultiIndex pandas DataFrame?

From Java

Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?

From Dev

how to multiply pandas dataframe with numpy array with broadcasting

From Dev

Convert Pandas Dataframe Date Index and Column to Numpy Array

From Dev

How do you use pandas.DataFrame columns as index, columns, and values?

From Dev

Replace values in numpy 2D array based on pandas dataframe

From Dev

how to use lists as values in pandas dataframe?

From Dev

Pandas dataframe indexing: Use of '.values' for different index occurrence frequencies

From Java

How to use sklearn fit_transform with pandas and return dataframe instead of numpy array?

From Dev

Pandas Divide dataframe by index values

From Dev

How to find boolean values of a column of numpy arrays in a pandas Dataframe?

From Dev

How to get sum of values grouped by the pandas DataFrame and make numpy matrix?

From Dev

How to create a column depending on the row index values in a multiindex pandas dataframe?

From Dev

How to create a column depending on the row index values in a multiindex pandas dataframe?

From Java

How do I convert a pandas Series or index to a Numpy array?

From Dev

Pandas DataFrame to Numpy Array ValueError

From Java

Pandas DataFrame to multidimensional NumPy Array

Related Related

  1. 1

    how to use values of a pandas DataFrame as numpy array index

  2. 2

    What index should I use to convert a numpy array into a pandas dataframe?

  3. 3

    Use pandas dataframe apply to replace row values from a numpy array

  4. 4

    Use index values as category values in pandas dataframe

  5. 5

    How to efficiently iterate a pandas DataFrame and increment a NumPy array on these values?

  6. 6

    How to add '$' to my pandas dataframe values and use a column as index?

  7. 7

    Accessing Pandas dataframe values when index values contained in separate numpy array

  8. 8

    Create Pandas dataframe from numpy array and use first column of the array as index

  9. 9

    replacing pandas dataframe variable values with a numpy array

  10. 10

    Modify pandas dataframe values with numpy array

  11. 11

    numpy array converted to pandas dataframe drops values

  12. 12

    How to exchange the role of values and index in pandas DataFrame?

  13. 13

    How to set index values in a MultiIndex pandas DataFrame?

  14. 14

    Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?

  15. 15

    how to multiply pandas dataframe with numpy array with broadcasting

  16. 16

    Convert Pandas Dataframe Date Index and Column to Numpy Array

  17. 17

    How do you use pandas.DataFrame columns as index, columns, and values?

  18. 18

    Replace values in numpy 2D array based on pandas dataframe

  19. 19

    how to use lists as values in pandas dataframe?

  20. 20

    Pandas dataframe indexing: Use of '.values' for different index occurrence frequencies

  21. 21

    How to use sklearn fit_transform with pandas and return dataframe instead of numpy array?

  22. 22

    Pandas Divide dataframe by index values

  23. 23

    How to find boolean values of a column of numpy arrays in a pandas Dataframe?

  24. 24

    How to get sum of values grouped by the pandas DataFrame and make numpy matrix?

  25. 25

    How to create a column depending on the row index values in a multiindex pandas dataframe?

  26. 26

    How to create a column depending on the row index values in a multiindex pandas dataframe?

  27. 27

    How do I convert a pandas Series or index to a Numpy array?

  28. 28

    Pandas DataFrame to Numpy Array ValueError

  29. 29

    Pandas DataFrame to multidimensional NumPy Array

HotTag

Archive