amChart4 - Change Top Horizontal Category Color - amcharts4

I have read all of documentation of amchart, can anyone please guide that how to change color of top horizontal categories text color.
const categoryAxis = subscriberChart.xAxes.push(
new am4charts.CategoryAxis()
);
categoryAxis.dataFields.category = 'date';
categoryAxis.renderer.opposite = true;
// Create value axis
const valueAxis = subscriberChart.yAxes.push(new am4charts.ValueAxis());
valueAxis.renderer.inversed = true;
//valueAxis.title.text = 'Place taken';
valueAxis.renderer.minLabelPosition = 0.01;
// Configure grid
valueAxis.renderer.grid.template.strokeOpacity = 1;
valueAxis.renderer.grid.template.stroke = am4core.color('#0071a5');
// Configure labels
valueAxis.renderer.labels.template.fill = am4core.color('#03a9f4');
// Create series
const userRegSeries = subscriberChart.series.push(
new am4charts.LineSeries()
);
https://codepen.io/faiwiz/pen/qBqNawW

The method to change it is the same as how you changed the value axis' text color - through the labels template inside the categoryAxis' renderer:
categoryAxis.renderer.labels.template.fill = am4core.color('#03a9f4');
initChartData = [
{
date: '02-06-2021',
usersReg: 59,
subscribers: 72,
subPercent: 69,
subRenew: 63,
subCancelled: 45,
pastDue: 83,
monthOn: 77,
},
{
date: '02-07-2021',
usersReg: 30,
subscribers: 66,
subPercent: 24,
subRenew: 61,
subCancelled: 40,
pastDue: 41,
monthOn: 76,
},
{
date: '02-08-2021',
usersReg: 78,
subscribers: 24,
subPercent: 69,
subRenew: 57,
subCancelled: 51,
pastDue: 23,
monthOn: 61,
},
{
date: '02-09-2021',
usersReg: 39,
subscribers: 77,
subPercent: 17,
subRenew: 52,
subCancelled: 53,
pastDue: 64,
monthOn: 82,
},
{
date: '02-10-2021',
usersReg: 29,
subscribers: 23,
subPercent: 49,
subRenew: 26,
subCancelled: 31,
pastDue: 28,
monthOn: 31,
},
{
date: '02-11-2021',
usersReg: 44,
subscribers: 33,
subPercent: 68,
subRenew: 73,
subCancelled: 100,
pastDue: 85,
monthOn: 95,
},
{
date: '02-12-2021',
usersReg: 96,
subscribers: 36,
subPercent: 84,
subRenew: 55,
subCancelled: 48,
pastDue: 62,
monthOn: 57,
},
{
date: '02-13-2021',
usersReg: 62,
subscribers: 61,
subPercent: 40,
subRenew: 91,
subCancelled: 58,
pastDue: 83,
monthOn: 38,
},
{
date: '02-14-2021',
usersReg: 77,
subscribers: 62,
subPercent: 41,
subRenew: 82,
subCancelled: 57,
pastDue: 31,
monthOn: 15,
},
{
date: '02-15-2021',
usersReg: 16,
subscribers: 58,
subPercent: 87,
subRenew: 47,
subCancelled: 83,
pastDue: 42,
monthOn: 13,
},
{
date: '02-16-2021',
usersReg: 97,
subscribers: 96,
subPercent: 88,
subRenew: 36,
subCancelled: 92,
pastDue: 95,
monthOn: 50,
},
{
date: '02-17-2021',
usersReg: 19,
subscribers: 78,
subPercent: 44,
subRenew: 20,
subCancelled: 97,
pastDue: 55,
monthOn: 57,
},
{
date: '02-18-2021',
usersReg: 89,
subscribers: 17,
subPercent: 70,
subRenew: 68,
subCancelled: 55,
pastDue: 35,
monthOn: 48,
},
{
date: '02-19-2021',
usersReg: 58,
subscribers: 98,
subPercent: 26,
subRenew: 34,
subCancelled: 10,
pastDue: 61,
monthOn: 41,
},
{
date: '02-20-2021',
usersReg: 35,
subscribers: 94,
subPercent: 24,
subRenew: 47,
subCancelled: 37,
pastDue: 45,
monthOn: 72,
},
{
date: '02-21-2021',
usersReg: 62,
subscribers: 66,
subPercent: 42,
subRenew: 85,
subCancelled: 12,
pastDue: 10,
monthOn: 69,
},
{
date: '02-22-2021',
usersReg: 38,
subscribers: 91,
subPercent: 56,
subRenew: 80,
subCancelled: 15,
pastDue: 42,
monthOn: 12,
},
{
date: '02-23-2021',
usersReg: 40,
subscribers: 76,
subPercent: 39,
subRenew: 75,
subCancelled: 59,
pastDue: 85,
monthOn: 91,
},
{
date: '02-24-2021',
usersReg: 22,
subscribers: 38,
subPercent: 44,
subRenew: 51,
subCancelled: 86,
pastDue: 31,
monthOn: 65,
},
{
date: '02-25-2021',
usersReg: 43,
subscribers: 80,
subPercent: 97,
subRenew: 52,
subCancelled: 69,
pastDue: 20,
monthOn: 84,
},
{
date: '02-26-2021',
usersReg: 62,
subscribers: 34,
subPercent: 47,
subRenew: 79,
subCancelled: 47,
pastDue: 81,
monthOn: 77,
},
{
date: '02-27-2021',
usersReg: 52,
subscribers: 90,
subPercent: 57,
subRenew: 66,
subCancelled: 44,
pastDue: 23,
monthOn: 75,
},
{
date: '02-28-2021',
usersReg: 16,
subscribers: 61,
subPercent: 22,
subRenew: 63,
subCancelled: 93,
pastDue: 99,
monthOn: 87,
},
{
date: '03-01-2021',
usersReg: 38,
subscribers: 44,
subPercent: 56,
subRenew: 23,
subCancelled: 51,
pastDue: 43,
monthOn: 85,
},
{
date: '03-02-2021',
usersReg: 83,
subscribers: 76,
subPercent: 15,
subRenew: 99,
subCancelled: 93,
pastDue: 18,
monthOn: 53,
},
{
date: '03-03-2021',
usersReg: 96,
subscribers: 33,
subPercent: 15,
subRenew: 45,
subCancelled: 47,
pastDue: 47,
monthOn: 69,
},
{
date: '03-04-2021',
usersReg: 42,
subscribers: 25,
subPercent: 94,
subRenew: 99,
subCancelled: 89,
pastDue: 79,
monthOn: 33,
},
{
date: '03-05-2021',
usersReg: 52,
subscribers: 26,
subPercent: 16,
subRenew: 53,
subCancelled: 52,
pastDue: 50,
monthOn: 49,
},
{
date: '03-06-2021',
usersReg: 94,
subscribers: 25,
subPercent: 16,
subRenew: 65,
subCancelled: 33,
pastDue: 86,
monthOn: 100,
},
{
date: '03-07-2021',
usersReg: 91,
subscribers: 29,
subPercent: 11,
subRenew: 30,
subCancelled: 48,
pastDue: 85,
monthOn: 56,
},
{
date: '03-08-2021',
usersReg: 50,
subscribers: 94,
subPercent: 87,
subRenew: 28,
subCancelled: 48,
pastDue: 75,
monthOn: 34,
},
{
date: '03-09-2021',
usersReg: 30,
subscribers: 90,
subPercent: 66,
subRenew: 78,
subCancelled: 16,
pastDue: 90,
monthOn: 84,
},
{
date: '03-10-2021',
usersReg: 25,
subscribers: 62,
subPercent: 23,
subRenew: 20,
subCancelled: 12,
pastDue: 57,
monthOn: 38,
},
{
date: '03-11-2021',
usersReg: 71,
subscribers: 53,
subPercent: 32,
subRenew: 34,
subCancelled: 81,
pastDue: 54,
monthOn: 41,
},
{
date: '03-12-2021',
usersReg: 31,
subscribers: 20,
subPercent: 31,
subRenew: 82,
subCancelled: 92,
pastDue: 38,
monthOn: 71,
},
{
date: '03-13-2021',
usersReg: 79,
subscribers: 77,
subPercent: 58,
subRenew: 45,
subCancelled: 59,
pastDue: 74,
monthOn: 22,
},
{
date: '03-14-2021',
usersReg: 91,
subscribers: 60,
subPercent: 96,
subRenew: 59,
subCancelled: 40,
pastDue: 74,
monthOn: 23,
},
{
date: '03-15-2021',
usersReg: 100,
subscribers: 92,
subPercent: 21,
subRenew: 22,
subCancelled: 40,
pastDue: 62,
monthOn: 26,
},
{
date: '03-16-2021',
usersReg: 54,
subscribers: 78,
subPercent: 92,
subRenew: 26,
subCancelled: 77,
pastDue: 56,
monthOn: 77,
},
{
date: '03-17-2021',
usersReg: 15,
subscribers: 93,
subPercent: 26,
subRenew: 96,
subCancelled: 31,
pastDue: 13,
monthOn: 48,
},
{
date: '03-18-2021',
usersReg: 49,
subscribers: 41,
subPercent: 96,
subRenew: 35,
subCancelled: 31,
pastDue: 78,
monthOn: 47,
},
{
date: '03-19-2021',
usersReg: 64,
subscribers: 73,
subPercent: 83,
subRenew: 25,
subCancelled: 85,
pastDue: 27,
monthOn: 39,
},
{
date: '03-20-2021',
usersReg: 71,
subscribers: 38,
subPercent: 66,
subRenew: 66,
subCancelled: 89,
pastDue: 98,
monthOn: 37,
},
{
date: '03-21-2021',
usersReg: 100,
subscribers: 16,
subPercent: 71,
subRenew: 73,
subCancelled: 68,
pastDue: 96,
monthOn: 62,
},
{
date: '03-22-2021',
usersReg: 66,
subscribers: 18,
subPercent: 82,
subRenew: 37,
subCancelled: 45,
pastDue: 73,
monthOn: 88,
},
{
date: '03-23-2021',
usersReg: 89,
subscribers: 17,
subPercent: 86,
subRenew: 89,
subCancelled: 68,
pastDue: 95,
monthOn: 90,
},
{
date: '03-24-2021',
usersReg: 74,
subscribers: 24,
subPercent: 77,
subRenew: 89,
subCancelled: 32,
pastDue: 88,
monthOn: 42,
},
{
date: '03-25-2021',
usersReg: 66,
subscribers: 18,
subPercent: 90,
subRenew: 18,
subCancelled: 76,
pastDue: 94,
monthOn: 83,
},
{
date: '03-26-2021',
usersReg: 82,
subscribers: 24,
subPercent: 44,
subRenew: 96,
subCancelled: 37,
pastDue: 50,
monthOn: 57,
},
{
date: '03-27-2021',
usersReg: 62,
subscribers: 72,
subPercent: 77,
subRenew: 51,
subCancelled: 70,
pastDue: 31,
monthOn: 13,
},
{
date: '03-28-2021',
usersReg: 10,
subscribers: 15,
subPercent: 90,
subRenew: 71,
subCancelled: 93,
pastDue: 94,
monthOn: 81,
},
{
date: '03-29-2021',
usersReg: 37,
subscribers: 38,
subPercent: 47,
subRenew: 92,
subCancelled: 30,
pastDue: 66,
monthOn: 29,
},
{
date: '03-30-2021',
usersReg: 74,
subscribers: 27,
subPercent: 88,
subRenew: 77,
subCancelled: 16,
pastDue: 99,
monthOn: 25,
},
{
date: '03-31-2021',
usersReg: 24,
subscribers: 77,
subPercent: 34,
subRenew: 100,
subCancelled: 36,
pastDue: 96,
monthOn: 28,
},
{
date: '04-01-2021',
usersReg: 82,
subscribers: 32,
subPercent: 59,
subRenew: 62,
subCancelled: 77,
pastDue: 79,
monthOn: 71,
},
{
date: '04-02-2021',
usersReg: 55,
subscribers: 97,
subPercent: 69,
subRenew: 45,
subCancelled: 29,
pastDue: 100,
monthOn: 63,
},
{
date: '04-03-2021',
usersReg: 80,
subscribers: 81,
subPercent: 97,
subRenew: 77,
subCancelled: 40,
pastDue: 75,
monthOn: 19,
},
{
date: '04-04-2021',
usersReg: 65,
subscribers: 26,
subPercent: 31,
subRenew: 33,
subCancelled: 42,
pastDue: 66,
monthOn: 16,
},
{
date: '04-05-2021',
usersReg: 74,
subscribers: 73,
subPercent: 56,
subRenew: 97,
subCancelled: 25,
pastDue: 62,
monthOn: 80,
},
{
date: '04-06-2021',
usersReg: 53,
subscribers: 21,
subPercent: 12,
subRenew: 45,
subCancelled: 39,
pastDue: 79,
monthOn: 17,
},
{
date: '04-07-2021',
usersReg: 100,
subscribers: 60,
subPercent: 16,
subRenew: 26,
subCancelled: 20,
pastDue: 28,
monthOn: 11,
},
{
date: '04-08-2021',
usersReg: 40,
subscribers: 76,
subPercent: 76,
subRenew: 33,
subCancelled: 90,
pastDue: 49,
monthOn: 25,
},
{
date: '04-09-2021',
usersReg: 97,
subscribers: 79,
subPercent: 37,
subRenew: 68,
subCancelled: 79,
pastDue: 61,
monthOn: 45,
},
{
date: '04-10-2021',
usersReg: 50,
subscribers: 89,
subPercent: 67,
subRenew: 89,
subCancelled: 87,
pastDue: 33,
monthOn: 54,
},
{
date: '04-11-2021',
usersReg: 45,
subscribers: 65,
subPercent: 80,
subRenew: 68,
subCancelled: 82,
pastDue: 67,
monthOn: 73,
},
{
date: '04-12-2021',
usersReg: 89,
subscribers: 45,
subPercent: 85,
subRenew: 59,
subCancelled: 24,
pastDue: 33,
monthOn: 95,
},
{
date: '04-13-2021',
usersReg: 41,
subscribers: 54,
subPercent: 74,
subRenew: 41,
subCancelled: 22,
pastDue: 82,
monthOn: 17,
},
{
date: '04-14-2021',
usersReg: 15,
subscribers: 39,
subPercent: 76,
subRenew: 16,
subCancelled: 74,
pastDue: 27,
monthOn: 47,
},
{
date: '04-15-2021',
usersReg: 39,
subscribers: 57,
subPercent: 90,
subRenew: 90,
subCancelled: 49,
pastDue: 58,
monthOn: 73,
},
{
date: '04-16-2021',
usersReg: 32,
subscribers: 32,
subPercent: 61,
subRenew: 26,
subCancelled: 73,
pastDue: 23,
monthOn: 11,
},
{
date: '04-17-2021',
usersReg: 23,
subscribers: 47,
subPercent: 92,
subRenew: 33,
subCancelled: 76,
pastDue: 84,
monthOn: 98,
},
{
date: '04-18-2021',
usersReg: 72,
subscribers: 89,
subPercent: 10,
subRenew: 90,
subCancelled: 82,
pastDue: 95,
monthOn: 60,
},
{
date: '04-19-2021',
usersReg: 71,
subscribers: 27,
subPercent: 78,
subRenew: 46,
subCancelled: 75,
pastDue: 68,
monthOn: 85,
},
{
date: '04-20-2021',
usersReg: 59,
subscribers: 44,
subPercent: 47,
subRenew: 20,
subCancelled: 29,
pastDue: 26,
monthOn: 70,
},
{
date: '04-21-2021',
usersReg: 79,
subscribers: 79,
subPercent: 70,
subRenew: 73,
subCancelled: 41,
pastDue: 66,
monthOn: 73,
},
{
date: '04-22-2021',
usersReg: 42,
subscribers: 23,
subPercent: 78,
subRenew: 20,
subCancelled: 24,
pastDue: 22,
monthOn: 25,
},
{
date: '04-23-2021',
usersReg: 34,
subscribers: 73,
subPercent: 11,
subRenew: 59,
subCancelled: 58,
pastDue: 22,
monthOn: 50,
},
{
date: '04-24-2021',
usersReg: 50,
subscribers: 39,
subPercent: 25,
subRenew: 33,
subCancelled: 82,
pastDue: 22,
monthOn: 52,
},
{
date: '04-25-2021',
usersReg: 27,
subscribers: 53,
subPercent: 76,
subRenew: 67,
subCancelled: 45,
pastDue: 40,
monthOn: 10,
},
{
date: '04-26-2021',
usersReg: 96,
subscribers: 58,
subPercent: 71,
subRenew: 32,
subCancelled: 51,
pastDue: 98,
monthOn: 37,
},
{
date: '04-27-2021',
usersReg: 10,
subscribers: 31,
subPercent: 79,
subRenew: 62,
subCancelled: 25,
pastDue: 43,
monthOn: 80,
},
{
date: '04-28-2021',
usersReg: 86,
subscribers: 26,
subPercent: 25,
subRenew: 76,
subCancelled: 18,
pastDue: 67,
monthOn: 16,
},
{
date: '04-29-2021',
usersReg: 58,
subscribers: 14,
subPercent: 100,
subRenew: 56,
subCancelled: 84,
pastDue: 75,
monthOn: 47,
},
{
date: '04-30-2021',
usersReg: 95,
subscribers: 65,
subPercent: 88,
subRenew: 61,
subCancelled: 84,
pastDue: 37,
monthOn: 47,
},
{
date: '05-01-2021',
usersReg: 99,
subscribers: 24,
subPercent: 77,
subRenew: 74,
subCancelled: 37,
pastDue: 55,
monthOn: 43,
},
{
date: '05-02-2021',
usersReg: 85,
subscribers: 89,
subPercent: 17,
subRenew: 41,
subCancelled: 67,
pastDue: 47,
monthOn: 54,
},
{
date: '05-03-2021',
usersReg: 36,
subscribers: 89,
subPercent: 34,
subRenew: 30,
subCancelled: 78,
pastDue: 68,
monthOn: 22,
},
{
date: '05-04-2021',
usersReg: 67,
subscribers: 68,
subPercent: 46,
subRenew: 59,
subCancelled: 50,
pastDue: 74,
monthOn: 76,
},
{
date: '05-05-2021',
usersReg: 18,
subscribers: 31,
subPercent: 13,
subRenew: 81,
subCancelled: 30,
pastDue: 54,
monthOn: 74,
},
{
date: '05-06-2021',
usersReg: 17,
subscribers: 91,
subPercent: 49,
subRenew: 84,
subCancelled: 94,
pastDue: 68,
monthOn: 57,
},
];
const subscriberChart = am4core.create(
'subscription-chart',
am4charts.XYChart
);
subscriberChart.data = this.initChartData;
const categoryAxis = subscriberChart.xAxes.push(
new am4charts.CategoryAxis()
);
categoryAxis.dataFields.category = 'date';
categoryAxis.renderer.opposite = true;
categoryAxis.renderer.labels.template.fill = am4core.color('#03a9f4');
// Create value axis
const valueAxis = subscriberChart.yAxes.push(new am4charts.ValueAxis());
valueAxis.renderer.inversed = true;
//valueAxis.title.text = 'Place taken';
valueAxis.renderer.minLabelPosition = 0.01;
// Configure grid
valueAxis.renderer.grid.template.strokeOpacity = 1;
valueAxis.renderer.grid.template.stroke = am4core.color('#0071a5');
// Configure labels
valueAxis.renderer.labels.template.fill = am4core.color('#03a9f4');
// Create series
const userRegSeries = subscriberChart.series.push(
new am4charts.LineSeries()
);
const userRegSeriesBulletsColors = '#ffc107';
userRegSeries.dataFields.valueY = 'usersReg';
userRegSeries.dataFields.categoryX = 'date';
userRegSeries.name = 'Registered Users';
userRegSeries.bullets.push(new am4charts.CircleBullet());
userRegSeries.tooltipText = '{valueY} {name} in {categoryX}';
userRegSeries.legendSettings.valueText = '{valueY}';
userRegSeries.stroke = am4core.color(userRegSeriesBulletsColors);
const subscribersSeries = subscriberChart.series.push(
new am4charts.LineSeries()
);
const subscribersSeriesBulletsColors = '#00b301';
subscribersSeries.dataFields.valueY = 'subscribers';
subscribersSeries.dataFields.categoryX = 'date';
subscribersSeries.name = 'Subscribers';
subscribersSeries.bullets.push(new am4charts.CircleBullet());
subscribersSeries.tooltipText = '{valueY} {name} in {categoryX}';
subscribersSeries.legendSettings.valueText = '{valueY}';
subscribersSeries.stroke = am4core.color(subscribersSeriesBulletsColors);
const subPercentSeries = subscriberChart.series.push(
new am4charts.LineSeries()
);
const subPercentSeriesBulletsColors = '#00bcd4';
subPercentSeries.dataFields.valueY = 'subPercent';
subPercentSeries.dataFields.categoryX = 'date';
subPercentSeries.name = 'Subscriber Percentage';
subPercentSeries.bullets.push(new am4charts.CircleBullet());
subPercentSeries.tooltipText = '{valueY} {name} in {categoryX}';
subPercentSeries.legendSettings.valueText = '{valueY}';
subPercentSeries.stroke = am4core.color(subPercentSeriesBulletsColors);
// Add chart cursor
subscriberChart.cursor = new am4charts.XYCursor();
subscriberChart.cursor.behavior = 'zoomY';
let hs1 = userRegSeries.segments.template.states.create('hover');
hs1.properties.strokeWidth = 5;
userRegSeries.segments.template.strokeWidth = 1;
userRegSeries.properties.fill = am4core.color(userRegSeriesBulletsColors);
let hs2 = subscribersSeries.segments.template.states.create('hover');
hs2.properties.strokeWidth = 5;
subscribersSeries.segments.template.strokeWidth = 1;
subscribersSeries.properties.fill = am4core.color(
subscribersSeriesBulletsColors
);
let hs3 = subPercentSeries.segments.template.states.create('hover');
hs3.properties.strokeWidth = 5;
subPercentSeries.segments.template.strokeWidth = 1;
subPercentSeries.properties.fill = am4core.color(
subPercentSeriesBulletsColors
);
// Add legend
subscriberChart.legend = new am4charts.Legend();
subscriberChart.legend.labels.template.fill = am4core.color('#252525');
subscriberChart.legend.valueLabels.template.fill = am4core.color('#252525');
#subscription-chart{
height:350px;
}
<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>
<script src="//www.amcharts.com/lib/4/themes/animated.js"></script>
<div id="subscription-chart" class="subscription-chart"></div>

Related

How to concat a tensor in pytorch?

What I want to do is something like this:
import torch
a = torch.arange(120).reshape(2, 3, 4, 5)
b = torch.cat(list(a), dim=2)
I want to know:
I have to convert tensor to a list, will this cause performance not good?
Even performance is OK, can I do this just with tensor?
You want to:
Reduce the number of copies: in this specific scenario, copies need to be made since we are rearranging the layout of our underlying data.
Reduce or remove any torch.Tensor -> non-torch.Tensor conversions: this will be a pain point when working with a GPU since you're transferring data in and out of the device.
You can perform the same operation by permuting the axes such that axis=0 goes to axis=-2 (the before the last axis), then flattening the last two axes:
>>> a.permute(1,2,0,3).flatten(-2)
tensor([[[ 0, 1, 2, 3, 4, 60, 61, 62, 63, 64],
[ 5, 6, 7, 8, 9, 65, 66, 67, 68, 69],
[ 10, 11, 12, 13, 14, 70, 71, 72, 73, 74],
[ 15, 16, 17, 18, 19, 75, 76, 77, 78, 79]],
[[ 20, 21, 22, 23, 24, 80, 81, 82, 83, 84],
[ 25, 26, 27, 28, 29, 85, 86, 87, 88, 89],
[ 30, 31, 32, 33, 34, 90, 91, 92, 93, 94],
[ 35, 36, 37, 38, 39, 95, 96, 97, 98, 99]],
[[ 40, 41, 42, 43, 44, 100, 101, 102, 103, 104],
[ 45, 46, 47, 48, 49, 105, 106, 107, 108, 109],
[ 50, 51, 52, 53, 54, 110, 111, 112, 113, 114],
[ 55, 56, 57, 58, 59, 115, 116, 117, 118, 119]]])

Implementing GIFT-COFB algorithm using Cryptol- list problem

I'm already new to Haskell with Cryptol dialect, also I'm irritated because I can't use loops...
I would like to implement array like this one... Initialization Matrix but I have the only idea to get every 4th element starting by [0] index and load this new list to S0. Similarly starting by 1 index of the list and load to new S1 array every 4th element.
Cryptol's type system is designed so that these sorts of bit splits that you find in crypto algorithms is almost trivial to express. And in fact, lack of loops is a plus, not a detriment, once you get used to that style.
There could be multiple ways to code your "initialization" code. But here's how I would go about it:
load : {a} [128][a] -> [4][32][a]
load(elts) = reverse (transpose cols)
where cols : [32][4][a]
cols = split elts
Note that the type here is more general than what you need, but it allows for easier testing. Here's what I get at the cryptol prompt:
Main> :set base=10
Main> load [127, 126 .. 0]
Showing a specific instance of polymorphic result:
* Using '7' for type argument 'a' of 'Main::load'
[[124, 120, 116, 112, 108, 104, 100, 96, 92, 88, 84, 80, 76, 72,
68, 64, 60, 56, 52, 48, 44, 40, 36, 32, 28, 24, 20, 16, 12, 8, 4,
0],
[125, 121, 117, 113, 109, 105, 101, 97, 93, 89, 85, 81, 77, 73, 69,
65, 61, 57, 53, 49, 45, 41, 37, 33, 29, 25, 21, 17, 13, 9, 5, 1],
[126, 122, 118, 114, 110, 106, 102, 98, 94, 90, 86, 82, 78, 74, 70,
66, 62, 58, 54, 50, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2],
[127, 123, 119, 115, 111, 107, 103, 99, 95, 91, 87, 83, 79, 75, 71,
67, 63, 59, 55, 51, 47, 43, 39, 35, 31, 27, 23, 19, 15, 11, 7, 3]]
This is a little hard to read, so here it is formatted:
[[124, 120, 116, 112, 108, 104, 100, 96, 92, 88, 84, 80, 76, 72, 68, 64, 60, 56, 52, 48, 44, 40, 36, 32, 28, 24, 20, 16, 12, 8, 4, 0],
[125, 121, 117, 113, 109, 105, 101, 97, 93, 89, 85, 81, 77, 73, 69, 65, 61, 57, 53, 49, 45, 41, 37, 33, 29, 25, 21, 17, 13, 9, 5, 1],
[126, 122, 118, 114, 110, 106, 102, 98, 94, 90, 86, 82, 78, 74, 70, 66, 62, 58, 54, 50, 46, 42, 38, 34, 30, 26, 22, 18, 14, 10, 6, 2],
[127, 123, 119, 115, 111, 107, 103, 99, 95, 91, 87, 83, 79, 75, 71, 67, 63, 59, 55, 51, 47, 43, 39, 35, 31, 27, 23, 19, 15, 11, 7, 3]]
which is exactly the structure you wanted. Now we can specialize:
loadBits : [128] -> [4][32]
loadBits(vector) = reverse (transpose cols)
where cols : [32][4]
cols = split vector
Note that the code is exactly the same as before, we just made it specific to the type you wanted.
Hope this gets you started!

Get file from AWS-S3

I have files(PDF and Image) in S3 bucket, and I am trying to download using
bucket.getObject(params, function(err, data)
I am getting the data in Uint8Array, How can I get it as a file??
in AWS properties of that file:
Content-Disposition : inline
Content-Type : application/pdf
Code:
const params = {
Bucket: 'mts-test-procedure-document',
Key: 'Key'
};
bucket.getObject(params, function(err, data){
if (err) {
console.log('There was an error getting your file: ', err);
return false;
}
console.log('Successfully got file.', data);
// return true;
});
Console:
Body: Uint8Array(94832) [37, 80, 68, 70, 45, 49, 46, 51, 13, 10, 37, 129, 150, 189, 221, 13, 10, 49, 32, 48, 32, 111, 98, 106, 13, 10, 60, 60, 32, 47, 84, 121, 112, 101, 32, 47, 67, 97, 116, 97, 108, 111, 103, 13, 10, 47, 80, 97, 103, 101, 115, 32, 50, 32, 48, 32, 82, 13, 10, 47, 79, 117, 116, 108, 105, 110, 101, 115, 32, 51, 32, 48, 32, 82, 13, 10, 62, 62, 13, 10, 101, 110, 100, 111, 98, 106, 13, 10, 52, 32, 48, 32, 111, 98, 106, 13, 10, 60, 60, 47, …]
ContentType: "application/pdf"
LastModified: Wed Sep 26 2018 15:34:59 GMT-0400 (Eastern Daylight Time) {}
Metadata: {}
You need to define while uploading your file .
For image
Content-Type: "image/jpeg"
for jpeg images
For pdf:
Content-Type: "application/pdf"
Content-Disposition: inline;
More content -type can be found at https://s3browser.com/features-content-mime-types-editor.aspx

Simple list comprehension (python 2.7)

I'm attempting to have the y list comprehension skip x if x =0 but the y list comprehension isn't producing the results I want.
x = [i for i in range(101)]
y = [i**2 for i in x if x>0]
So the output should be something like this:
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
>>> y
[ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000]
However, I'm still getting a 0 in the y list.
Thanks.
x = [i for i in range(101)]
y = [i**2 for i in x if i>0]
Note i > 0. You can think of the part that comes right after the "for" as the members of the set you are interested in, and the part after "in" as the set you are selecting from.

How to use regular expression to match square brackets of values and store in python dictionary?

I have a data and want to get the results stored in a python dictionary as below:
#example mydicdata[key] = values in the brackets
#example mydicdata[0] = [""]
#example mydicdata[7] = ['0', '1', '2', '3', '4', '5', '6', '7'... ]
import re
data = "{0=[], 1=[], 2=[], 3=[], 4=[], 5=[], 6=[], 7=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103], 8=[], 9=[], 10=[], 11=[], 12=[], 13=[], 14=[], 15=[], 16=[], 17=[], 18=[], 19=[], 20=[], 21=[], 22=[], 23=[], 24=[], 25=[], 26=[], 27=[], 28=[], 29=[], 30=[], 31=[], 32=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103], 33=[], 34=[], 35=[], 36=[], 37=[], 38=[], 39=[], 40=[], 41=[], 42=[], 43=[], 44=[], 45=[], 46=[], 47=[], 48=[], 49=[], 50=[], 51=[], 52=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103], 53=[], 54=[], 55=[], 56=[], 57=[], 58=[], 59=[], 60=[], 61=[], 62=[], 63=[], 64=[], 65=[], 66=[], 67=[], 68=[], 69=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103], 70=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103], 71=[], 72=[], 73=[], 74=[], 75=[], 76=[], 77=[], 78=[], 79=[], 80=[], 81=[], 82=[], 83=[], 84=[], 85=[], 86=[], 87=[], 88=[88], 89=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103], 90=[], 91=[], 92=[], 93=[], 94=[], 95=[], 96=[], 97=[], 98=[], 99=[], 100=[], 101=[], 102=[], 103=[]}"
data = data[1:-1]
temp = re.split(r'[\d=/[[0-9?,/d?/]]]',data)
I think I'm almost there, but the result I got here is a big chunk of list 0=[]....,103[].
Could you please give me the guideline?
Thank you.
this is a way to do it without regex: your data string is almost python (just need to replace the = by :); then ast.literal_eval can turn the string into a python dictionary:
from ast import literal_eval
data = '''{ 0=[], 1=[], 2=[], 3=[], 4=[], 5=[], 6=[],
7=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103], 8=[], 9=[],
10=[], 11=[], 12=[], 13=[], 14=[], 15=[], 16=[], 17=[], 18=[]
# more data
}'''
dct = literal_eval(data.replace('=', ':'))
print dct[0] # -> []
print dct[7] # -> [0, 1, 2, 3, 4,...,100, 101, 102, 103]