How to create Heat Map without creating so many arrays for Z

I have a very large dataset and creating a heatmap with the z value being arrays takes too much time.
Is there any way I can set it where I loop through the x values and say specific y values have this z value for this x value. I am not sure if I explained this well enough let me know if I can clarify anything.

This is an example of how the plotly tutorial sets up heat maps but not related to my code. What I want to do is instead of having the Z values be represented in arrays for me to be able to say a specific x value and y value have this Z value since I have a large data set and because not all x values and y values will have a z value (that specific one will be 0). Right now how it works is notice how there are 3 z value arrays and 3 y value and each array of z values has 5 values one for each value. This wont work for me because I have 500+ x and y values.

public graph = {
    data: [
    {z: [[1, 20, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]],
    x: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
    y: ['Morning', 'Afternoon', 'Evening'],
    type: 'heatmap'}
    layout: {
      autosize: true,
      xaxis: {
      side: 'top'

Heatmap traces accept x/y/z 1D columns as valid inputs as well.

See example JS code: which renders as

Am I able to do this if my X and Y need to be strings and not integers?
Hemanth Kalathil

This method would work a lot better for me if that is possible to still have X and Y as strings

Both string and numeric coordinates will work.